oslo.messaging/oslo_messaging/_executors
Matthew Booth 3f3c489aaf Fix a race calling blocking MessageHandlingServer.start()
This fixes a race due to the quirkiness of the blocking executor. The
blocking executor does not create a separate thread, but is instead
explicitly executed in the calling thread. Other threads will,
however, continue to interact with it.

In the non-blocking case, the executor will have done certain
initialisation in start() before starting a worker thread and
returning control to the caller. That is, the caller can be sure that
this initialisation has occurred when control is returned. However, in
the blocking case, control is never returned. We currently work round
this by setting self._running to True before executing executor.start,
and by not doing any locking whatsoever in MessageHandlingServer.
However, this current means there is a race whereby executor.stop()
can run before executor.start(). This is fragile and extremely
difficult to reason about robustly, if not currently broken.

The solution is to split the initialisation from the execution in the
blocking case. executor.start() is no longer a blocking operation for
the blocking executor. As for the non-blocking case, executor.start()
returns as soon as initialisation is complete, indicating that it is
safe to subsequently call stop(). Actual execution is done explicitly
via the new execute() method, which blocks.

In doing this, we also make FakeBlockingThread a more complete
implementation of threading.Thread. This fixes a related issue in
that, previously, calling server.wait() on a blocking executor from
another thread would not wait for the completion of the executor. This
has a knock-on effect in test_server's ServerSetupMixin. This mixin
created an endpoint with a stop method which called server.stop().
However, as this is executed by the executor, and also joins the
executor thread, which is now blocking, this results in a deadlock. I
am satisfied that, in general, this is not a sane thing to do.
However, it is useful for these tests. We fix the tests by making the
stop method non-blocking, and do the actual stop and wait calls from
the main thread.

Change-Id: I0d332f74c06c22b44179319432153e15b69f2f45
2015-10-21 09:43:52 +01:00
..
__init__.py Move files out of the namespace package 2015-01-12 12:50:41 -05:00
base.py Provide the executor 'wait' function a timeout and use it 2015-09-08 15:53:31 +00:00
impl_aioeventlet.py add plugin documentation for executors and notifiers 2015-07-20 18:30:00 +00:00
impl_blocking.py Fix a race calling blocking MessageHandlingServer.start() 2015-10-21 09:43:52 +01:00
impl_eventlet.py Update 'impl_eventlet' docstring to reflect actual impl. 2015-07-17 12:42:20 -07:00
impl_pooledexecutor.py Provide the executor 'wait' function a timeout and use it 2015-09-08 15:53:31 +00:00
impl_thread.py Executor docstring & attribute tweaks 2015-07-14 15:43:04 +00:00