Add additional logging to subscribe route and simplify calling client_connected#2998
Merged
Conversation
…t_connected` Out-of-band discussions with the BitCraft team brought up questions about whether it was possible for a rejected client connection to start an expensive computation like a subscription before their connection was killed, e.g. by sending a `Subscribe` message along the WebSocket before `client_connected` had finished returning `Err`. I don't believe this was actually possible, as `ClientConnection::spawn` called and awaited `call_identity_connected` before invoking its `actor` closure, and it was that `actor` which processed `Subscribe` messages. But it was somewhat difficult to verify that behavior, and so I re-organized the code so that the outer layer of the `subscribe` handler obviously had that property without having to step into `ClientConnection::spawn`. I also added some additional logging to the subscribe route, including the `X-Forwarded-For` header in more messages, as the BitCraft team complained about having difficulty correlating IP addresses with connections. The log levels remain the same as before, just with additional information added: - Successful connections are at `debug` level, - Rejected connections are at `info` level (these are the ones BitCraft cares about in this case). - Failed connections are at `warn`. As the levels are unchanged, this should not add undesirable log noise.
kim
approved these changes
Jul 29, 2025
Contributor
kim
left a comment
There was a problem hiding this comment.
Looks reasonable to me. fwiw, there is a smoketest that tests rejection via the client_connected reducer.
- Add `struct Connected` which acts as a "proof" of having called `client_connected`, rather than just relying on docstrings to enforce correct usage. - Drop a log that prints on successful connections to `debug`, in keeping with the PR description. - Slap the prefix `websocket: ` into log messages for easier filtering.
mamcx
pushed a commit
that referenced
this pull request
Aug 26, 2025
…t_connected` (#2998) # Description of Changes Out-of-band discussions with the BitCraft team brought up questions about whether it was possible for a rejected client connection to start an expensive computation like a subscription before their connection was killed, e.g. by sending a `Subscribe` message along the WebSocket before `client_connected` had finished returning `Err`. I don't believe this was actually possible, as `ClientConnection::spawn` called and awaited `call_identity_connected` before invoking its `actor` closure, and it was that `actor` which processed `Subscribe` messages. But it was somewhat difficult to verify that behavior, and so I re-organized the code so that the outer layer of the `subscribe` handler obviously had that property without having to step into `ClientConnection::spawn`. I also added some additional logging to the subscribe route, including the `X-Forwarded-For` header in more messages, as the BitCraft team complained about having difficulty correlating IP addresses with connections. The log levels remain the same as before, just with additional information added: - Successful connections are at `debug` level, - Rejected connections are at `info` level (these are the ones BitCraft cares about in this case). - Failed connections are at `warn`. As the levels are unchanged, this should not add undesirable log noise. # API and ABI breaking changes N/a # Expected complexity level and risk 3? The `subscribe` route was complex and remains so. I believe this change simplifies the code and makes the logic more obvious, but reviewers should take care to verify that the behavior actually is equivalent as I believe. # Testing - [ ] I would like a test deployment of BitCraft to staging or something, or to include this patch in the next bot test that we do anyways, just for sanity's sake.
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.
Description of Changes
Out-of-band discussions with the BitCraft team brought up questions about whether it was possible for a rejected client connection to start an expensive computation like a subscription before their connection was killed, e.g. by sending a
Subscribemessage along the WebSocket beforeclient_connectedhad finished returningErr.I don't believe this was actually possible, as
ClientConnection::spawncalled and awaitedcall_identity_connectedbefore invoking itsactorclosure, and it was thatactorwhich processedSubscribemessages. But it was somewhat difficult to verify that behavior, and so I re-organized the code so that the outer layer of thesubscribehandler obviously had that property without having to step intoClientConnection::spawn.I also added some additional logging to the subscribe route, including the
X-Forwarded-Forheader in more messages, as the BitCraft team complained about having difficulty correlating IP addresses with connections. The log levels remain the same as before, just with additional information added:debuglevel,infolevel (these are the ones BitCraft cares about in this case).warn.As the levels are unchanged, this should not add undesirable log noise.
API and ABI breaking changes
N/a
Expected complexity level and risk
3? The
subscriberoute was complex and remains so. I believe this change simplifies the code and makes the logic more obvious, but reviewers should take care to verify that the behavior actually is equivalent as I believe.Testing