mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-18 07:18:20 +00:00
Simpler, more correct process lifecycle handling.
The previous version included a bogus hack where we just passed `allow_missing=True` when finalization was requested of `_run_node`. This was clearly wrong since if the caller asked for finalization, it's a programming error for it to already have been done. Fortunately we have a perfectly good finalizer already, `TahoeProcess.kill`, which we can use instead of trying to craft a finalizer out of the various pieces that make up that value. Also, nothing seems to use the `_protocol` attribute set by `got_proto` so let's just drop that.
This commit is contained in:
@ -254,10 +254,18 @@ class TahoeProcess(object):
|
|||||||
_cleanup_process_async(self.transport, allow_missing=False)
|
_cleanup_process_async(self.transport, allow_missing=False)
|
||||||
return self.transport.exited
|
return self.transport.exited
|
||||||
|
|
||||||
def restart_async(self, reactor, request):
|
def restart_async(self, reactor: IReactorProcess, request: Any) -> Deferred:
|
||||||
|
"""
|
||||||
|
Stop and then re-start the associated process.
|
||||||
|
|
||||||
|
:return: A Deferred that fires after the new process is ready to
|
||||||
|
handle requests.
|
||||||
|
"""
|
||||||
d = self.kill_async()
|
d = self.kill_async()
|
||||||
d.addCallback(lambda ignored: _run_node(reactor, self.node_dir, request, None, finalize=False))
|
d.addCallback(lambda ignored: _run_node(reactor, self.node_dir, request, None, finalize=False))
|
||||||
def got_new_process(proc):
|
def got_new_process(proc):
|
||||||
|
# Grab the new transport since the one we had before is no longer
|
||||||
|
# valid after the stop/start cycle.
|
||||||
self._process_transport = proc.transport
|
self._process_transport = proc.transport
|
||||||
d.addCallback(got_new_process)
|
d.addCallback(got_new_process)
|
||||||
return d
|
return d
|
||||||
@ -290,19 +298,17 @@ def _run_node(reactor, node_dir, request, magic_text, finalize=True):
|
|||||||
)
|
)
|
||||||
transport.exited = protocol.exited
|
transport.exited = protocol.exited
|
||||||
|
|
||||||
if finalize:
|
tahoe_process = TahoeProcess(
|
||||||
request.addfinalizer(partial(_cleanup_tahoe_process, transport, protocol.exited, allow_missing=True))
|
|
||||||
|
|
||||||
# XXX abusing the Deferred; should use .when_magic_seen() pattern
|
|
||||||
|
|
||||||
def got_proto(proto):
|
|
||||||
transport._protocol = proto
|
|
||||||
return TahoeProcess(
|
|
||||||
transport,
|
transport,
|
||||||
node_dir,
|
node_dir,
|
||||||
)
|
)
|
||||||
protocol.magic_seen.addCallback(got_proto)
|
|
||||||
return protocol.magic_seen
|
if finalize:
|
||||||
|
request.addfinalizer(tahoe_process.kill)
|
||||||
|
|
||||||
|
d = protocol.magic_seen
|
||||||
|
d.addCallback(lambda ignored: tahoe_process)
|
||||||
|
return d
|
||||||
|
|
||||||
|
|
||||||
def _create_node(reactor, request, temp_dir, introducer_furl, flog_gatherer, name, web_port,
|
def _create_node(reactor, request, temp_dir, introducer_furl, flog_gatherer, name, web_port,
|
||||||
|
Reference in New Issue
Block a user