In tor-proto, can manually closing a StreamTarget collide with dropping it?
Right now there are two paths into the circuit reactor's close_stream()
method:
- First, from
run_once()
when it gets aOk(None)
from a StreamTarget, indicating that the StreamTarget has dropped its half of the mpsc::Sender. - Second, from
handle_control()
when it gets aClosePendingStream
control message, indicating that theStreamTarget
has been manually closed fromIncomingStream::reject()
viaStreamTarget::close()
.
I think that it's possible for both of those paths to get triggered for the same stream.
But if we call close_stream()
twice on the same stream, the reactor will panic in StreamMap::terminate()
.
Here is a thought: perhaps we should just remove StreamTarget::close()
and CtrlMsg::ClosePendingStream
, and handle IncomingStream::reject()
by dropping the StreamTarget?
(Found while working on a branch to make StreamTarget::close()
safer to use. I'll link this ticket with that MR, since it clarifies stuff and adds comments.)