-
Notifications
You must be signed in to change notification settings - Fork 296
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
rpcserver: Convert ws client lifecycle to context. #3025
rpcserver: Convert ws client lifecycle to context. #3025
Conversation
This is a minor change to only cast the request method once when parsing a JSON-RPC command.
@@ -124,8 +125,7 @@ func (s *Server) WebsocketHandler(conn *websocket.Conn, remoteAddr string, authe | |||
return | |||
} | |||
s.ntfnMgr.AddClient(client) | |||
client.Start() | |||
client.WaitForShutdown() | |||
client.Run(context.TODO()) |
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.
A todo here to pass down the dcrd parent context to synchronize lifecycles would be good.
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.
Disregard, just noticed this is being done in #3026.
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.
Message for commit rpcserver: Consistent block connected ntfn skip.
has typo.
[...] no longer relevant due to the change to the filters are handled some time ago.
This updates the websocket notification manager block connected handler to skip creation of the associated notification when no clients have requested it inside of the handler instead of prior to it so it is consistent with the rest of the handlers. It was previously done outside of the handler in order to skip a bunch of work that is no longer relevant due to the change to the filters some time ago.
This modifies the lifecycle of websocket clients to use the expected pattern for running subsystems based on contexts. In particular, this replaces the Start and WaitForShutdown methods with a single method named Run and arranges for it to block until the provided context is cancelled. This is more flexible for the caller since it can easily turn blocking code into async code while the reverse is not true. The new Run method waits for all goroutines that it starts to shutdown before returning to help ensure an orderly shutdown. Since there are exported methods that send messages to the output and notification handler goroutines via channels and those goroutines are stopped during the shutdown process, all sends select across both the channels in question as well as a quit channel which is closed when the context it cancelled. This ensures callers can't end up blocking on send to a goroutine that is no longer running without needing additional mutexes.
32e2937
to
d75cc6b
Compare
Fixed. |
This requires #3024.This modifies the lifecycle of websocket clients to use the expected pattern for running subsystems based on contexts.
In particular, this replaces the
Start
andWaitForShutdown
methods with a single method namedRun
and arranges for it to block until the provided context is cancelled. This is more flexible for the caller since it can easily turn blocking code into async code while the reverse is not true.The new
Run
method waits for all goroutines that it starts to shutdown before returning to help ensure an orderly shutdown.Since there are exported methods that send messages to the output and notification handler goroutines via channels and those goroutines are stopped during the shutdown process, all sends select across both the channels in question as well as a quit channel which is closed when the context it cancelled. This ensures callers can't end up blocking on send to a goroutine that is no longer running without needing additional mutexes.
It also contains a couple of other minor consistency cleanup commits.