Changeset 1d32326 in trunk


Ignore:
Timestamp:
2023-01-17T15:06:14Z (2 years ago)
Author:
Jean-Paul Calderone <exarkun@…>
Branches:
master
Children:
290bb52
Parents:
eb630c39
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified integration/util.py

    reb630c39 r1d32326  
    255255        return self.transport.exited
    256256
    257     def restart_async(self, reactor, request):
     257    def restart_async(self, reactor: IReactorProcess, request: Any) -> Deferred:
     258        """
     259        Stop and then re-start the associated process.
     260
     261        :return: A Deferred that fires after the new process is ready to
     262            handle requests.
     263        """
    258264        d = self.kill_async()
    259265        d.addCallback(lambda ignored: _run_node(reactor, self.node_dir, request, None, finalize=False))
    260266        def got_new_process(proc):
     267            # Grab the new transport since the one we had before is no longer
     268            # valid after the stop/start cycle.
    261269            self._process_transport = proc.transport
    262270        d.addCallback(got_new_process)
     
    291299    transport.exited = protocol.exited
    292300
     301    tahoe_process = TahoeProcess(
     302        transport,
     303        node_dir,
     304    )
     305
    293306    if finalize:
    294         request.addfinalizer(partial(_cleanup_tahoe_process, transport, protocol.exited, allow_missing=True))
    295 
    296     # XXX abusing the Deferred; should use .when_magic_seen() pattern
    297 
    298     def got_proto(proto):
    299         transport._protocol = proto
    300         return TahoeProcess(
    301             transport,
    302             node_dir,
    303         )
    304     protocol.magic_seen.addCallback(got_proto)
    305     return protocol.magic_seen
     307        request.addfinalizer(tahoe_process.kill)
     308
     309    d = protocol.magic_seen
     310    d.addCallback(lambda ignored: tahoe_process)
     311    return d
    306312
    307313
Note: See TracChangeset for help on using the changeset viewer.