Skip to content

files: await pending stream writes before closing the handle - #337018

Merged
Christof Marti (chrmarti) merged 2 commits into
mainfrom
chrmarti/fix-buffered-stream-write-completion
Sep 21, 2026
Merged

Christof Marti (chrmarti) merged 2 commits into
mainfrom
chrmarti/fix-buffered-stream-write-completion

Conversation

@chrmarti

@chrmarti Christof Marti (chrmarti) commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fix the buffered file-write race behind the macOS / Electron failure on #336992.

A stream can emit end or error while its asynchronous onData write is still pending. FileService previously settled the stream operation immediately and closed the provider handle before the write finished. This can leave the disk provider retrying a write against a closed handle, and can incorrectly report success when the pending write subsequently fails.

The CI log reports two teardown failures under ExtHostAuthentication / createIfNone - false, but the leaked cancellation listeners originate in the preceding file-service work (doWriteBuffer -> disk write retry -> timeout). The second failure is the console-output guard reacting to the leak report. The notebook-only changes in #336992 are unrelated.

Changes

  • Serialize pending stream writes and await them before settling on end/error.
  • Use one completion handler for stream end, stream error, and write failure; preserve the first observed error while waiting for pending writes, and stop resuming the stream afterward.
  • Add deterministic deferred-write regressions covering successful completion, a late provider-write failure, a stream error, and a stream error followed by a write failure.

Incoming PR check

No overlapping fix found. In particular:

Validation

  • Before the fix: all 3 new regression cases fail; the handle closes before the write finishes, and the late write error is lost.
  • The combined-failure regression failed against the initial fix and now passes, preserving the earlier stream error.
  • After the fix: file-service and in-memory file-service unit suites: 33 passing.
  • Disk file-service and extension-host authentication integration suites: 198 passing, 6 pending.
  • npm run gulp compile-client: 0 errors.
  • ESLint on both changed files, git diff --check, and commit hygiene: passed.

Local validation was on Windows. macOS-specific confirmation is left to PR CI.

Wait for buffered stream writes on end and error so the provider handle remains open and late write errors are propagated. Cover success, write failure, and stream failure with deferred-write regression tests.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings September 21, 2026 11:04

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.

Copilot review overview

🟢 Approval recommended

The narrow lifecycle fix correctly preserves write errors and handle ordering with focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes a file-service race by waiting for asynchronous stream writes before closing provider handles.

Changes:

  • Serializes pending buffered writes and delays stream settlement.
  • Prevents resuming completed or failed streams.
  • Adds regression tests for success, write failure, and stream failure.
File Description
src/​vs/​platform/​files/​common/​fileService.ts Awaits pending writes before resolving or rejecting.
src/​vs/​platform/​files/​test/​browser/​fileService.test.ts Adds deterministic stream-write race coverage.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Use one completion handler for stream end, stream error, and write failure. Wait for pending writes without replacing an earlier stream error, and cover combined stream/write failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@chrmarti
Christof Marti (chrmarti) merged commit 5c8826f into main Sep 21, 2026
33 checks passed
@chrmarti
Christof Marti (chrmarti) deleted the chrmarti/fix-buffered-stream-write-completion branch September 21, 2026 13:32
@vs-code-engineering vs-code-engineering Bot added this to the 1.140.0 milestone Sep 21, 2026
Christof Marti (chrmarti) added a commit that referenced this pull request Sep 21, 2026
Add regression coverage for buffered chunk serialization, partial writes, producer backpressure, peeked prefixes, empty streams, and queued writes following provider or stream failures. Follow up on #337018 without changing production code.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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