[2.1] Deferred being returned from thread
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
MAAS |
Invalid
|
Critical
|
Unassigned |
Bug Description
Seen in a log file somewhere:
Unhandled Error
Traceback (most recent call last):
File "/usr/lib/
line 364, in startReactor
self.config, oldstdout, oldstderr, self.profiler, reactor)
File "/usr/lib/
line 285, in runReactorWithL
reactor.run()
File "/usr/lib/
1194, in run
self.
File "/usr/lib/
1203, in mainLoop
self.
--- <exception caught here> ---
File "/usr/lib/
798, in runUntilCurrent
f(*a, **kw)
File "/usr/lib/
line 392, in callback
assert not isinstance(result, Deferred)
builtins.
This:
File "/usr/lib/
798, in runUntilCurrent
f(*a, **kw)
is calling a function that's been put into the reactor via
callFromThread. I've inspected all uses of this in MAAS and they're
fine. However, this:
File "/usr/lib/
line 392, in callback
assert not isinstance(result, Deferred)
tells us that the `f` earlier is a bound Deferred.callback method.
Looking at Twisted's source code there is exactly one function that does
callFromThread(
of that in MAAS! Do we have a winner?
No. Unfortunately, Twisted's deferToThread calls deferToThreadPool, and
there are 32 uses of that in MAAS, so more investigation is necessary.
It seems very likely that somewhere in MAAS a Deferred is being returned
from a non-reactor thread. That's almost certainly broken code in its
own right, never mind that it's crashing on the way back into the
reactor.
The effect of this bug may be to permanently leave a Deferred unfired.
It can be reproduced with a simple script that will not exit until you
kill it:
from twisted.
from twisted.
from twisted.
def run(reactor):
return deferToThread(
react(run)
Related branches
- Blake Rouse (community): Approve
-
Diff: 245 lines (+105/-27)7 files modifiedsrc/maasserver/populate_tags.py (+1/-2)
src/maasserver/tests/test_populate_tags.py (+1/-1)
src/maasserver/utils/threads.py (+6/-4)
src/provisioningserver/monkey.py (+16/-0)
src/provisioningserver/tests/test_monkey.py (+32/-18)
src/provisioningserver/utils/tests/test_twisted.py (+27/-0)
src/provisioningserver/utils/twisted.py (+22/-2)
description: | updated |
Changed in maas: | |
milestone: | none → 2.1.0 |
summary: |
- Deferred being returned from thread + [2.1] Deferred being returned from thread |
Changed in maas: | |
milestone: | 2.1.0 → 2.1.1 |
Changed in maas: | |
milestone: | 2.1.1 → 2.1.2 |
Changed in maas: | |
milestone: | 2.1.2 → 2.1.3 |
Dear user,
This is an automated message.
We believe this bug report is no longer an issue in the latest version of MAAS. For such reason, we are making this issue as Won't Fix. If you believe this issue is still present in the latest version of MAAS, please re-open this bug report.