fix(server): hold RLock when reading activeUploads in handleChunkedUpload#2175
Open
wilfredmulenga wants to merge 2 commits intomainfrom
Open
fix(server): hold RLock when reading activeUploads in handleChunkedUpload#2175wilfredmulenga wants to merge 2 commits intomainfrom
wilfredmulenga wants to merge 2 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a concurrency issue in chunked split-upload handling by protecting access to the activeUploads map with an RLock, and adds unit tests around split-upload session behavior.
Changes:
- Add
RLock/RUnlockaroundactiveUploads[fileID]lookup inhandleChunkedUpload. - Reuse the session read once (instead of re-reading the map) to avoid inconsistent reads.
- Add tests for concurrent access patterns,
UpdateSessionchunk tracking, andCleanupSession.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
server/internal/app/file_split_uploader.go |
Protects activeUploads map read in handleChunkedUpload and uses the read session consistently. |
server/internal/app/file_split_uploader_test.go |
Introduces tests for concurrency patterns and session bookkeeping/cleanup. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…load Concurrent chunk uploads could trigger a fatal Go runtime crash because activeUploads was read at line 115 without holding the mutex, while UpdateSession and cleanupStaleSessions write to it under a lock. Also fixes a nil pointer dereference: the old code re-read activeUploads[fileID] to get the Project, which could be nil if a concurrent goroutine had only partially written the session. The session is now read once under RLock and reused safely. Adds tests covering concurrent map access (run with -race), session chunk tracking, and cleanup behaviour. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
- Extract readSessionProjectID helper so the test exercises the real production read path rather than duplicating the lock pattern - Guard session.Project nil before calling .ID() — a non-zero chunk arriving before chunk 0 creates the session with Project == nil - Remove unused chunkNum parameter from concurrent access test goroutine Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
6787ac1 to
10ddf0f
Compare
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.
Fixes a fatal crash where concurrent chunk uploads caused a Go runtime map race in
handleChunkedUpload. Also guards against a nil pointer if a non-zero chunk arrives before chunk 0 has set the project. Adds tests verified clean undergo test -race.Reported in: https://github.com/eukarya-inc/compliance/issues/7 (REL-01)