Ref T10811. Currently, we can emit the "willExit" event multiple times, or emit it and then emit a "log" event.
This causes some problems with the Phabricator listener, which cleans up resources the first time it sees this event. When it gets the second copy (or logs afterward) it fails to process events.
Instead, emit it only once we're actually cleaning up the daemon handle. This guarantees it emits last and emits exactly once.
I believe this only cleans up logs, but it's possible it also improves stability.