Repository navigation
fix(transport): log directly sent envelopes in DebugTransport - #3113
Merged
Merged
Conversation
solnic
marked this pull request as ready for review
October 6, 2026 12:32
solnic
added this pull request to stack #3114
October 6, 2026 12:46
sl0thentr0py
approved these changes
Oct 6, 2026
solnic
force-pushed
the
fix/debug-transport-log-envelopes
branch
from
October 6, 2026 13:07
7cb926e to
5037e14
Compare
|
|
||
| def send_envelope(envelope) | ||
| log_envelope(envelope) | ||
| backend.send_envelope(envelope) |
There was a problem hiding this comment.
Bug: The logged_envelopes method can crash with an unhandled JSON::ParserError due to concurrent writes to the debug log file corrupting JSON data.
Severity: HIGH
Suggested Fix
Implement file locking using File#flock around the write operation to ensure atomic writes. Additionally, wrap the JSON.parse(line) call within the logged_envelopes method in a begin/rescue JSON::ParserError block to gracefully handle any corrupted lines and prevent crashes.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: sentry-ruby/lib/sentry/transport/debug_transport.rb#L32
Potential issue: The `DebugTransport` writes to a log file using `File.open(log_file,
"a")` without any file locking. In multi-threaded environments, such as with SolidQueue
workers, concurrent writes can corrupt the log file, especially with large payloads. The
`logged_envelopes` method reads these logs and attempts to parse each line with
`JSON.parse` but lacks a `rescue` block. If a line is corrupted due to interleaved
writes, `JSON.parse` will raise an unhandled `JSON::ParserError`, causing the method to
crash. The existing `fully_written?` check is insufficient as it only verifies a
trailing newline and does not prevent JSON corruption from race conditions.
Also affects:
sentry-ruby/lib/sentry/transport/debug_transport.rb:64~64
Did we get this right? 👍 / 👎 to inform future reviews.
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.
DebugTransportnow also logs envelopes passed tosend_envelope, such as logs and metrics, not only events. Several processes can write to the log file at once, so each envelope is written in one go and reading skips any unfinished last line.I stumbled upon this when working on #3057 as SolidQueue workers caused issues with concurrent writing to this debug transport log.