Skip to content

fix: decouple pin polling context from upload context deadline#99

Merged
pcfreak30 merged 2 commits into
developfrom
fix/upload-poll-timeout
Jul 3, 2026
Merged

fix: decouple pin polling context from upload context deadline#99
pcfreak30 merged 2 commits into
developfrom
fix/upload-poll-timeout

Conversation

@pcfreak30

@pcfreak30 pcfreak30 commented Jul 3, 2026

Copy link
Copy Markdown
Member

Summary

  • Create a fresh context with the configured upload timeout for all pin operations (ListOperations, WaitForOperation, and pin verification retry) instead of reusing the upload context that may have already consumed most of its deadline
  • Pass explicit poll options (WithPollInterval, WithPollTimeout) to WaitForOperation instead of relying on SDK defaults that race against the parent context
  • Added regression test verifying pin polling continues after the parent context is cancelled

Summary

This PR fixes an issue where pin polling could fail prematurely because it reused the upload context, whose deadline may have been nearly exhausted by the time pinning started. Since server-side pin processing (e.g., DAG block downloads) can take longer than the upload itself, the inherited deadline was too short.

Changes

  • Decoupled pin polling context: waitForPin now creates a fresh context with the configured upload timeout instead of reusing the parent upload context, preventing premature cancellation when the upload context deadline is nearly consumed.
  • Added explicit poll configuration: WaitForOperation is now called with a 2-second poll interval and the upload timeout as the poll timeout, making polling behavior explicit and consistent.
  • Updated all downstream calls within waitForPin (operation status checks and pin status verification retries) to use the new fresh context.
  • Added test coverage: A new test verifies that pin polling completes successfully even when the parent context is already cancelled, confirming the fresh context is used for polling.

The upload handler wraps the entire upload+pin flow in a single 5-minute
context. By the time waitForPin starts polling, most of the deadline is
already consumed. When the parent context expires, in-flight GetOperation
HTTP calls are cancelled mid-flight, producing context deadline exceeded.

Create a fresh context with the configured upload timeout for all pin
operations (ListOperations, WaitForOperation, and pin verification retry).
Pass explicit poll options to WaitForOperation instead of relying on SDK
defaults that race against the parent context.
@kody-ai

kody-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Code Review Could Not Complete ⚠️

The review failed before suggestions could be generated.

Reason: Unexpected error while running the code review (openai_compatible).

After fixing the issue, comment @kody review on this PR to re-run the review.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown

Code Coverage Report

Total Coverage: 53.6%

Generated from commit: 90b968c
Repository: LumeWeb/pinner-cli

@pcfreak30

Copy link
Copy Markdown
Member Author

@kody review

@kody-ai

kody-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Code Review Could Not Complete ⚠️

The review failed before suggestions could be generated.

Reason: Unexpected error while running the code review (openai_compatible).

After fixing the issue, comment @kody review on this PR to re-run the review.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@pcfreak30

Copy link
Copy Markdown
Member Author

@kody review

@kody-ai

This comment has been minimized.

Comment thread pkg/cli/upload_client.go Outdated
@pcfreak30

Copy link
Copy Markdown
Member Author

@kody review

Address Kody review: context.Background() ignored parent cancellation
(Ctrl+C/SIGINT). Use a goroutine that only propagates context.Canceled,
not deadline expiry, so pin polling gets a fresh full timeout while user
cancellation still aborts it.

Add test verifying user cancellation propagates to pin polling.
@pcfreak30

Copy link
Copy Markdown
Member Author

Addressed Kody's review in b4ff03f.

The fix now distinguishes between user cancellation (Ctrl+C/SIGINT, context.Canceled) and parent deadline expiry (context.DeadlineExceeded). A goroutine watches ctx.Done() and only propagates explicit cancellation, so:

  • Pin polling gets a fresh full timeout (decoupled from the upload's consumed deadline)
  • User cancellation still aborts pin polling immediately
  • Parent deadline expiry doesn't prematurely cancel pin polling

Added a second test case (propagates user cancellation to pin polling) that verifies Ctrl+C aborts the poll loop.

@kody-ai

This comment has been minimized.

@pcfreak30

Copy link
Copy Markdown
Member Author

@kody review

@kody-ai

kody-ai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Validate Business Logic: Ask Kody to validate your code against business rules by adding a comment with the @kody -v business-logic command.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug
Performance
Security
Business Logic

Access your configuration settings here.

@pcfreak30 pcfreak30 merged commit 2a7c7e9 into develop Jul 3, 2026
10 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.

1 participant