Skip to content

fix(audio): unblock chunked reader close during chunk prefetch#304

Merged
devgianlu merged 3 commits intodevgianlu:masterfrom
gjermundgaraba:fix/audio-chunked-reader-close-race
Apr 15, 2026
Merged

fix(audio): unblock chunked reader close during chunk prefetch#304
devgianlu merged 3 commits intodevgianlu:masterfrom
gjermundgaraba:fix/audio-chunked-reader-close-race

Conversation

@gjermundgaraba
Copy link
Copy Markdown
Contributor

This PR fixes a shutdown race in the audio chunked reader that I noticed in the CI run for another PR I opened: #302

Changes are essentially:

  • switch chunked reader shutdown to context-based cancellation
  • cancel in-flight HTTP requests and retry backoff when Close() is called
  • remove per-chunk error state and simplify chunk fetch coordination
  • prevent prefetch goroutines from being started after shutdown begins
  • make ReadAt fail fast with net.ErrClosed once the reader is closed
  • make latency metric collection concurrency-safe
  • unit and integration tests

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes shutdown races and close behavior in the audio HTTP chunked reader by switching to context-based cancellation, ensuring in-flight requests/backoff are cancelable, and making latency metrics concurrency-safe; adds/updates unit + integration coverage around close/cancel behavior.

Changes:

  • Introduce reader-scoped context.Context cancellation; normalize post-close failures to net.ErrClosed and prevent new prefetch goroutines during shutdown.
  • Simplify chunk coordination by removing per-chunk error state and tightening fetch/prefetch synchronization.
  • Add unit/integration tests covering close cancellation of in-flight fetches/reads and related concurrency behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
audio/chunked-reader.go Context-cancelable shutdown, fetch/prefetch coordination changes, latency metric locking/snapshotting
audio/chunked-reader_internal_test.go Unit tests for Close() interactions with concurrent fetch, in-flight requests, and transport/body read behavior
audio/chunked-reader_integration_test.go Integration tests refactor + new close-cancels-in-flight-read coverage

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread audio/chunked-reader.go
Comment thread audio/chunked-reader_internal_test.go
@devgianlu devgianlu merged commit 3dfea66 into devgianlu:master Apr 15, 2026
8 checks passed
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.

3 participants