Skip to content

fix(nzbfs): bind file context to HTTP request context and reduce server WriteTimeout - #816

Open
DarkseidAM wants to merge 2 commits into
javi11:mainfrom
DarkseidAM:fix/webdav-idle-watchdog-timeout
Open

fix(nzbfs): bind file context to HTTP request context and reduce server WriteTimeout#816
DarkseidAM wants to merge 2 commits into
javi11:mainfrom
DarkseidAM:fix/webdav-idle-watchdog-timeout

Conversation

@DarkseidAM

@DarkseidAM DarkseidAM commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

This PR addresses an issue where WebDAV reads can hang indefinitely when Usenet segment downloads stall or network connections drop silently.

Root Cause

  1. Unbounded WebDAV server timeout: http.Server.WriteTimeout was hardcoded to 30 * time.Minute in setup.go. If a client (rclone) timed out and dropped the connection, Altmount kept the response goroutine open for up to 30 minutes.
  2. Decoupled file context: OpenFile passed a context that did not automatically cancel when an HTTP request disconnected.

Changes

  1. Request-bound File Context: Wrapped OpenFile context in a child context derived from the HTTP request context (fileCtx, cancel := context.WithCancel(ctx)), ensuring client disconnects automatically cancel in-flight UsenetReader downloads.
  2. HTTP Server WriteTimeout: Reduced server WriteTimeout in setup.go from 30 minutes to 3 minutes to automatically close idle/stalled HTTP streams.

@javi11

javi11 commented Aug 10, 2026

Copy link
Copy Markdown
Owner

I think this can be achieve by seting up a context with cancel timeout on open the file, you don't need any watchdog

@DarkseidAM
DarkseidAM force-pushed the fix/webdav-idle-watchdog-timeout branch from ded1bd6 to b02ecc9 Compare August 10, 2026 16:22
@DarkseidAM

Copy link
Copy Markdown
Contributor Author

Refactored as suggested in the force-push: removed the per-file startIdleWatchdog goroutine entirely.

The PR now relies on:

  1. context.WithCancel(r.Context()) bound to each OpenFile handle so HTTP client disconnects immediately propagate cancellation to in-flight NNTP segment downloads.
  2. Reduced HTTP server WriteTimeout (3 minutes) in setup.go to ensure idle/stalled HTTP response streams auto-close and cancel their request context.

…er WriteTimeout

- Wrap OpenFile context in request-derived child context so HTTP client disconnects automatically cancel in-flight UsenetReader downloads
- Reduce http.Server WriteTimeout from 30 minutes to 3 minutes in setup.go to prevent orphaned HTTP connections
@DarkseidAM
DarkseidAM force-pushed the fix/webdav-idle-watchdog-timeout branch from b02ecc9 to 805d063 Compare August 10, 2026 16:25
@DarkseidAM DarkseidAM changed the title fix(nzbfs): add per-file idle progress watchdog and reduce server WriteTimeout fix(nzbfs): bind file context to HTTP request context and reduce server WriteTimeout Aug 10, 2026
@javi11

javi11 commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Now you add this cancelCtx but you don't use it anywhere

@DarkseidAM

DarkseidAM commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

Apologies, forgot to stage the commit
Updated MetadataVirtualFile.Close() to invoke mvf.cancelCtx() when the file handle is closed.

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.

2 participants