Skip to content

Pin Hyrax version for chunk upload fix - #359

Merged
ShanaLMoore merged 9 commits into
mainfrom
chunk-upload-fix
Jul 11, 2025
Merged

Pin Hyrax version for chunk upload fix#359
ShanaLMoore merged 9 commits into
mainfrom
chunk-upload-fix

Conversation

@ShanaLMoore

@ShanaLMoore ShanaLMoore commented Jul 10, 2025

Copy link
Copy Markdown
Contributor

Story

image

Expected Behavior Before Changes

Unable to upload a file larger than 20MB

image (3) image (4)

Expected Behavior After Changes

The file fully uploads

image

Comment thread bundler.d/example.rb Outdated
In multi-pod environments with a shared file system, chunked uploads were failing due to a race condition. The file size was being read from a cache, which could be stale if another pod had recently written a chunk. This resulted in an incorrect size check, causing parts of the file to be overwritten.

This commit fixes the issue by changing how the file size is retrieved. It now opens the file for reading to get the current size directly from the file handle, bypassing any filesystem attribute caching. This ensures an accurate size check and prevents file corruption during chunked uploads.
@ShanaLMoore
ShanaLMoore requested a review from Copilot July 11, 2025 14:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR pins the Hyrax gem to a specific commit and applies a fix for chunked uploads by decorating the UploadsController.

  • Switches injection of bundler.d from an environment variable to a symlink in the Dockerfile.
  • Adds a Bundler override to pin hyrax to a specific Git ref in bundler.d/example.rb.
  • Implements a controller decorator to read file size directly and prevent stale cache corruption during chunked uploads.

Reviewed Changes

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

File Description
docker-compose.yml Removes BUNDLE_BUNDLER_INJECT__GEM_PATH env var and updates volumes
Dockerfile Replaces copying bundler.d with a symlink to /app/.bundler.d
bundler.d/example.rb Pins hyrax gem to commit d6330a1c048bd498da852325a502f8dba0467c11
app/controllers/hyrax/uploads_controller_decorator.rb Adds decorator to fix a race condition in chunked uploads
Comments suppressed due to low confidence (3)

app/controllers/hyrax/uploads_controller_decorator.rb:9

  • The new chunk upload logic should be covered by unit or integration tests to ensure correct behavior when begin_of_chunk matches current_size and when it doesn't.
    def handle_chunk(content_range, chunk)

docker-compose.yml:16

  • Since the BUNDLE_BUNDLER_INJECT__GEM_PATH environment variable is removed, consider mounting the bundler.d directory as a volume so that local gem overrides are applied in development.
    - BUNDLE_DISABLE_LOCAL_BRANCH_CHECK=true

Dockerfile:5

  • [nitpick] Consider adding a comment explaining why a symlink is used instead of copying bundler.d, so future maintainers understand the reasoning.
RUN ln -s /app/samvera/bundler.d /app/.bundler.d

Comment thread app/controllers/hyrax/uploads_controller_decorator.rb Outdated
Comment thread app/controllers/hyrax/uploads_controller_decorator.rb Outdated
Refactors the chunked upload process to prevent file corruption in multi-pod environments.
- Gets the file size by opening the file (File.open + size) to bypass stale filesystem attribute caches (e.g., on NFS).
- Replaces the system sync command with the more precise and idiomatic IO#fsync to ensure each chunk is flushed to disk before the next operation proceeds.
Comment thread bundler.d/example.rb
ensure_gem "sentry-ruby"
ensure_gem "sentry-rails"
ensure_gem "cancancan", "~> 3.0" # cancancan is bundling to v1.17.0 but we need at least 3.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This approach keeps the submodule’s Hyku version pinned to 315925a4 (the version currently deployed to production) while still incorporating the chunk upload fix by specifying the Hyrax version in bundler.d/example.

The decorator code is in hyrax now, sha ab4d108114289822b186579cd73a53d68c145a73
@ShanaLMoore
ShanaLMoore marked this pull request as ready for review July 11, 2025 16:24
@ShanaLMoore
ShanaLMoore requested a review from kirkkwang July 11, 2025 16:24
@ShanaLMoore

Copy link
Copy Markdown
Contributor Author
image

@ShanaLMoore

Copy link
Copy Markdown
Contributor Author

Manual

image

Bulkrax

image image

@ShanaLMoore
ShanaLMoore merged commit 903f643 into main Jul 11, 2025
7 checks passed
@ShanaLMoore
ShanaLMoore deleted the chunk-upload-fix branch July 11, 2025 18:58
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