Skip to content

client/webserver: connect and update client map under lock#575

Merged
chappjc merged 1 commit into
decred:masterfrom
chappjc:webserver-client-listen-random-bind
Aug 3, 2020
Merged

client/webserver: connect and update client map under lock#575
chappjc merged 1 commit into
decred:masterfrom
chappjc:webserver-client-listen-random-bind

Conversation

@chappjc
Copy link
Copy Markdown
Member

@chappjc chappjc commented Jul 30, 2020

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.

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.
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)
Copy link
Copy Markdown
Member Author

@chappjc chappjc Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Member Author

@chappjc chappjc Jul 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@chappjc
Copy link
Copy Markdown
Member Author

chappjc commented Aug 3, 2020

Everything is failing without this, so I'm merging now.

@chappjc chappjc merged commit be176ba into decred:master Aug 3, 2020
@chappjc chappjc deleted the webserver-client-listen-random-bind branch August 3, 2020 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants