Gateway concurrency
This pull request is most easily digested going commit-to-commit. They are pretty cleanly separated.
I went through and fixed up a lot of the concurrency patterns in the gateway. None of the changes have proper tests, but all of the old tests are still passing. Several deadlocks have been removed, and the biggest offenders in terms of quick-shutdown have been removed.
Some things remain on my todo list:
-
threadedListenPeer
is not fixed up yet, it violates the 'don't hold atg.Add()
for long periods of time` rule, and has some other weirdness to the concurrency that I don't like. -
managedConnectNewPeer
,managedConnectOldPeer
,managedAcceptConnectNewPeer
, andmanagedAcceptConnectOldPeer
all don't support quick-shutdown. I may have slipped in a goroutine here or there that is not being correctly closed with regards to these functions, can clean that up tomorrow. -
threadedHandleConn
does not yet support clean shutdown.
I am considering abandoning the pursuit of clean shutdown for the code that does not have it yet. The biggest offenders have already been addressed. That would just leave threadedListenPeer
on my todo list.
Oh, and testing, as a lot of this code is not tested well, even though the whole test suite is passing.