client/webserver: connect and update client map under lock#575
Merged
chappjc merged 1 commit intoAug 3, 2020
Merged
Conversation
Make webserver connect and clients map update atomic so that any connected client will be found in the map when accessed under lock, and vice versa. Bind the webserver to a random port in tests. Remove dead code.
chappjc
commented
Jul 30, 2020
| var shutdown func() | ||
| ctx, killCtx := context.WithCancel(tCtx) | ||
| s, err := New(c, fmt.Sprintf("localhost:%d", tPort), tLogger, false) | ||
| s, err := New(c, "127.0.0.1:0", tLogger, false) |
Member
Author
There was a problem hiding this comment.
Parallel test runs of the client/websocket package are possible now. s.addr gives the actual host:port used.
Comment on lines
+80
to
+84
| // Lock the clients map before starting the connection listening so that | ||
| // synchronized map accesses are guaranteed to reflect this connection. | ||
| // Also, ensuring only live connections are in the clients map notify from | ||
| // sending before it is connected. | ||
| s.mtx.Lock() |
Member
Author
There was a problem hiding this comment.
It may seem that this is only for the assumption in TestClientMap, but it is a good test since a wsConn handler may be written to expect the client in the map and the handlers may be called as soon as the connection is up. Having the connect and map insert be atomic assures this.
JoeGruffins
approved these changes
Aug 2, 2020
Member
Author
|
Everything is failing without this, so I'm merging now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make webserver connect and clients map update atomic so that any
connected client will be found in the map when accessed under lock,
and vice versa.
Bind the webserver to a random port in tests.
Remove dead code.