-
Notifications
You must be signed in to change notification settings - Fork 16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but we may want to consider reusing the existing goroutines. That is, either:
- Have one goroutine wait for the other to finish and make it responsible for cleaning up.
- Have both goroutines check/set an atomic counter. When the counter reaches 0, that goroutine does the cleanup.
usually, I'd say to just stick with an extra goroutine. However, we have a lot of goroutines here.
But I do like the idea of the atomic counter, it's more code but totally obviates the need for the extra goroutine. |
Alright, implemented with an atomic counter. |
@@ -364,10 +369,18 @@ func (r *Relay) handleHopStream(s inet.Stream, msg *pb.CircuitRelay) { | |||
|
|||
r.addLiveHop(src.ID, dst.ID) | |||
|
|||
goroutines := new(int32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that this is allocated on the heap to avoid lingering the original goroutine stack.
This adds connection manager tagging for peers with live hops.
Note the extra supervisory goroutine in the hop, as we need to ensure both sides are closed before removing the tag and reduce the live hop count.
Closes #65