-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix critical bugs in session opening for TCP and UDP in case of Singleplex mode. #145
Conversation
…eplex mode. - In case of TCP, don't open the session in the listener accept thread. This causes resource exhaustion of the tcp listener backlog queue in case of internet connection disruption or timeout. - In case of UDP, don't create a new session for every UDP packet.
Travis says there's a data race in the integration test, but I think it's a bug in the test. |
Codecov Report
@@ Coverage Diff @@
## master #145 +/- ##
==========================================
- Coverage 67.62% 67.48% -0.15%
==========================================
Files 37 37
Lines 2400 2405 +5
==========================================
Hits 1623 1623
- Misses 615 618 +3
- Partials 162 164 +2
Continue to review full report at Codecov.
|
Sorry it took me a while to get back to this. I agree that for singleplexing TCP, the new session function should be called inside the newly created goroutine. The behaviour with UDP is slightly trickier because there isn't a strict sense of connection. Currently Cloak assumes each incoming ip:port pair represents a "connection", which may not be correct to begin with |
The race condition also exists here, where SessionId in authInfo is written to. Previously this seshMaker() is always called by a single goroutine so this is fine, now we need to copy authInfo from the outside scope to a local variable Cloak/cmd/ck-client/ck-client.go Lines 171 to 178 in 7b6a82b
|
Just some small changes - passing newSeshFunc as an argument to the goroutine function isn't necessary because we are not mutating the variable, we are only reading it. Also I don't think the explicit variable of multiplexSession is necessary. For TCP, the variable becomes local on entry to the goroutine function (despite the name shadowing), and for UDP there isn't any concurrency in session opening anyway. I hope that still gives the right behaviours |
I considered it as an optimization to avoid allocation of an object to hold the variables captured in the closure, passing it as a parameter reduces memory use (object allocation on every time the goroutine is called).
It is not technically necessary but it makes the code clearer and it clarifies the intention of what we are doing.
The problem in UDP was that it was opening a new session for every packet, not a concurrency issue.
I will review and test. |
@cbeuw ok i tested tcp singleplex and multiplex, udp singleplex and multiplex and seems to work. |
In case of TCP, don't open the session in the listener accept thread. This
causes resource exhaustion of the tcp listener backlog queue in case of internet
connection disruption or timeout.
In case of UDP, don't create a new session for every UDP packet.
This also fixes cbeuw/Cloak-android#17 and corrects a lot of wrong behaviors.
@cbeuw Please check and merge, and I recommend a new release.