tor-chanmgr: improve channel cleanup
There are two cases I can think of where it would be nice to improve channel cleanup:
-
A pending channel entry is added to the channel map, the code then
await
s for the channel to be established, and then removes the pending channel from the channel map and adds the new open channel instead. If any code returns early (for example withreturn
or?
) between when the pending channel entry is added and when it's removed, the pending channel will stay in the channel map forever. I believe this will cause all future attempts to get a channel to that target to fail. Currently there's only one situation where this can happen (an internal error is returned), but it would be easy to accidentally introduce other returns that forget to clean up the pending channel. (edit: I see another?
has appeared in the code, so there are two places now where this happens.) -
When an open channel is closed, it's not immediately removed from the channel map. The closed channel will remain in the channel map until
expire_channels
eventually/periodically runs and removes it.
It would be nice for pending channels to have a handle, where dropping the handle removes the pending channel from the channel map. And it would be nice if open channels signaled when they were closed, and then the channel manager would remove them from the map after receiving the signal.
This can also help us better keep track of channels and in-use sockets for #1603.