[QGIS-Developer] QGIS Server plugins and thread safety

Martin Dobias wonder.sk at gmail.com
Sun Nov 19 08:39:02 PST 2017


Hi Alessandro

On Sun, Nov 19, 2017 at 10:34 AM, Alessandro Pasotti <apasotti at gmail.com> wrote:
> Hi,
>
> mi recent experiments with multi-threaded python wrappers for QGIS server
> showed a critical flaw in my original implementation of the server plugins.
>
> First, I want to stress that this is not a problem in FCGI server
> implementation but only if the server is used directly from python in a
> multi threaded server implementation.
>
> The problem is that the server interface that exposes the request handler is
> a static property of the interface, that is changed on every request.
> This means that there is a race condition in setting/accessing the handler
> from a plugin filter, and that a plugin filter might access to the handler
> for a wrong request.

I think this is probably just the tip of the iceberg: most of the
classes in qgis_core are not thread-safe, and I believe the
implementation of server's services is not expected to be run in
multiple threads at once either. So even though things in theory could
work if requests are handled in multiple threads, most likely there
will be crashes. Even though map rendering was made to run safe in
multiple worker threads, there is still the assumption that the map
rendering is started from the main thread where all the objects live
(I'm talking about the QObject-based classes). Dealing with objects
like map layers or project in non-main thread is likely to end up
badly.

I would say for now we should simply stick with handling only one
request per server process at a time - just like how it is done with
the FastCGI implementation.

Cheers
Martin


More information about the QGIS-Developer mailing list