fix(live_view_hook): handle Bandit.TransportError and URI struct in connect_info#1062
Merged
solnic merged 2 commits intoMay 20, 2026
Merged
Conversation
…onnect_info Wrap `get_connect_info/2` calls in `try/rescue` to gracefully handle `Bandit.TransportError` when the WebSocket transport is already closed during mount (fixes getsentry#1025). Convert `socket.host_uri` to a string with `URI.to_string/1` before storing it in request context, preventing JSON encoding failures when `:uri` is not included in `connect_info` (fixes getsentry#1040). Also sanitize non-JSON-encodable values in `:request` during event rendering as defense-in-depth. Co-Authored-By: OpenCode <noreply@opencode.ai>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2e9fe8c. Configure here.
77ed5a2 to
142dbdc
Compare
…tionale Expand the moduledoc to explain what each connect_info key provides and that the hook still works when keys are omitted. Add a comment to the try/rescue in get_connect_info_if_root/2 explaining why we rescue broadly (Bandit is optional and we must never crash the LiveView process). Co-Authored-By: OpenCode <noreply@opencode.ai>
142dbdc to
06e0918
Compare
solnic
approved these changes
May 20, 2026
Collaborator
solnic
left a comment
There was a problem hiding this comment.
Thanks for tackling this 🙇🏻
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.

Summary
Fixes two related issues in
Sentry.LiveViewHookthat affect Bandit + LiveView production deployments:on_mountcrashes withBandit.TransportErrorwhen the client disconnects during mount.%URI{}structs inconnect_infofail JSON encoding.Changes
lib/sentry/live_view_hook.exget_connect_info(socket, key)inget_connect_info_if_root/2with atry/rescuethat returnsnilon any transport error. This mirrors the existing defensive pattern inSentry.PlugContext(seeremote_port/1).socket.host_urito a string withURI.to_string/1before storing it in Sentry request context. Previously, when:uriwas omitted fromconnect_info, the raw%URI{}struct remained in context and caused JSON encoding to fail later in the pipeline.lib/sentry/client.exsanitize_non_jsonable_values/2on the:requestfield during event rendering, consistent with how:extra,:user, and:tagsare already sanitized.Tests
SentryTest.EndpointNoUriandSentry.LiveViewHookNoUriTestto verify hook behavior when:uriis absent fromconnect_info.Client.render_event/1sanitizing non-JSON-encodable values in:request.Verification
mix test— 813 tests, 0 failuresmix format --check-formatted— cleanmix compile --warnings-as-errors— cleanRelated Issues