Skip to content

fix(blobstore): stop a local write when its request is cancelled - #3394

Merged
Quick104 merged 2 commits into
mainfrom
fix/blobstore-stop-cancelled-writes
Nov 2, 2026
Merged

Quick104 merged 2 commits into
mainfrom
fix/blobstore-stop-cancelled-writes

Conversation

@Quick104

@Quick104 Quick104 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: N/A
Validation tasks: none

The local filesystem blob store kept writing after the caller's context was
cancelled. A write stuck on a slow body or a slow disk could finish and
publish its file after the request that started it had given up, and a write
cancelled mid-stream could report "file already closed" instead of a context
error. This change makes cancellation stop the write, never publish after
cancellation, and report the cancellation.

Approach

publish closes the temporary file when the context ends and keeps that
guard armed through the final Sync. It checks the context again just before
the rename or link that publishes the file. When cancellation closed the file,
the error is the context's cause, wrapping any write or sync error. The
deferred cleanup removes the temporary file as before. Every PutStream and
CreateExclusive caller gets this; the S3 store already stopped on
cancellation.

Validation

  • Go build, go vet, and changed-line lint: pass.
  • The cancellation test (nothing published, context error returned, no
    temporary file left) passes, including 1,000 repeated runs under -race.
  • The rest of the blobstore tests pass.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/pr-3394/

Risks

A single write or sync call already blocked in the kernel, such as on a hung
network mount, cannot be interrupted from Go; closing the file makes the next
call fail and nothing is published. Callers that passed a context ending
right after the body was read now get an error instead of a published file;
none was found among existing callers.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: T3 Code with Claude Code
  • Tool(s): Claude Code with subagents; OpenAI Codex CLI for independent review
  • Model(s): claude-opus-5-5; gpt-6.1-sol (review)
  • Involvement: Fully AI-generated. The maintainer tested the backups work it came from on a development server; the diff awaits human review.
  • Adversarial review: gpt-6.1-sol reviewed the backups work read-only in repeated rounds; every finding was fixed or answered before this branch was cut.

🤖 Generated with Claude Code

Note

Fix Filesystem.publish to stop writing and skip publish on cancellation

Adds a context cancellation callback in filesystem.go that closes the temporary file during a write or sync. publish then returns the context cause, and after syncing it checks the context again before renaming the temporary file into place.

  • Adds TestFilesystemCanceledStreamIsNeverPublished with a cancelingReader that cancels mid-stream; the test verifies the error is context.Canceled, Stat returns ErrNotFound, and the uploads directory stays empty

Macroscope summarized aa68209.

A local-storage write that its caller cancelled, for example when a request
deadline passed, kept writing and syncing its temporary file and then
published it under the key. A write or sync stalled on the disk now fails
once the context ends, the temporary file is removed, and nothing is
published after the caller gave up.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@silo-triage silo-triage Bot added the size/M 50–199 added + deleted lines (all files); change volume, not priority. label Nov 2, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T01:42:08.187170Z aa68209 New commits
🔒 Security Review ✅ Completed 2026-11-02T01:43:24.858818Z aa68209 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@silo-kody

silo-kody Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 762f0bd5-aeb9-4994-865c-cfcbd45a4810
Commits

Reviewing files that changed from the base of the PR and between 2904e9c and aa68209.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ed01ca4-dc32-4185-b7f3-4af65b43b11d
Commits

Reviewing files that changed from the base of the PR and between 7e0765b and 2904e9c.

Files selected for processing: 2
  • internal/blobstore/filesystem.go
  • internal/blobstore/filesystem_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Walkthrough

Filesystem publishing now closes the temporary file when the context is canceled during a write or sync. It returns the context cause and checks for cancellation before renaming. A new test verifies that a canceled upload leaves no object or upload-directory entries.

Changes: Filesystem publishing

Layer / File(s) Summary
Cancellation handling during publish
internal/blobstore/filesystem.go, internal/blobstore/filesystem_test.go
Filesystem.publish closes the temporary file on cancellation and checks cancellation before renaming. The test checks the returned error and confirms that no object or upload-directory entries remain.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: dannyshafer

Merge Risk: Minimal · previous review 2904e

Cancellation is checked before publication. No merge-blocking issue was established.

Security architecture risk: Minimal · up to 2904e

The change improves cancellation handling without introducing a new endpoint, privilege, or storage boundary. No material security regression was identified. Cancellation can still race with the final rename, but that possibility existed before this change and is narrowed rather than expanded.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The affected authority remains the existing filesystem backend's ability to publish blobs under its configured root through Put and PutStream. The comparison introduces no additional caller, identity transition, or destination authority.

Resilience and Maintainability Implications

  • observed — The added test cancels while delivering the final input bytes and asserts a cancellation error, no published object, and no remaining upload-directory entries. It does not establish behavior in the final check-to-rename interval or prove interruption of an already blocked input read or kernel operation.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: stopping local blob-store writes when the request context is cancelled.
Description check Passed The description directly explains the cancellation problem, implementation approach, validation, and risks for the filesystem blob-store changes.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 2 files.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish labels Nov 2, 2026
@Quick104
Quick104 merged commit 9e66f6a into main Nov 2, 2026
22 checks passed
@Quick104
Quick104 deleted the fix/blobstore-stop-cancelled-writes branch November 2, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code priority: P2 Limited scope, workaround exists, or polish size/M 50–199 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant