Skip to content

fix: add mutex protection to etagResponseWriter#71

Merged
alexferl merged 1 commit intomasterfrom
etag
Mar 10, 2026
Merged

fix: add mutex protection to etagResponseWriter#71
alexferl merged 1 commit intomasterfrom
etag

Conversation

@alexferl
Copy link
Copy Markdown
Owner

The etagResponseWriter had a potential data race on the buffer field
and state fields (hasWritten, written, skipETag, finalized) when
Write() and Flush() were called concurrently.

Changes:

  • Add sync.Mutex to etagResponseWriter struct
  • Create writeHeaderLocked(), writeLocked(), finalizeLocked() internal methods
  • Update public methods (WriteHeader, Write, Flush, finalize) to use locking
  • Add TestETag_ConcurrentWriteAndFlush to verify thread safety

  The etagResponseWriter had a potential data race on the buffer field
  and state fields (hasWritten, written, skipETag, finalized) when
  Write() and Flush() were called concurrently.

  Changes:
  - Add sync.Mutex to etagResponseWriter struct
  - Create writeHeaderLocked(), writeLocked(), finalizeLocked() internal methods
  - Update public methods (WriteHeader, Write, Flush, finalize) to use locking
  - Add TestETag_ConcurrentWriteAndFlush to verify thread safety

Signed-off-by: alexferl <me@alexferl.com>
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22927677831

Details

  • 25 of 25 (100.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.07%) to 93.526%

Files with Coverage Reduction New Missed Lines %
sse.go 2 93.88%
Totals Coverage Status
Change from base Build 22927420302: 0.07%
Covered Lines: 8119
Relevant Lines: 8681

💛 - Coveralls

@alexferl alexferl merged commit 55acccd into master Mar 10, 2026
9 checks passed
@alexferl alexferl deleted the etag branch March 10, 2026 22:47
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