Skip to content

fix(oxfmt): Use tokio::stdin/out to handle WouldBlock error#17946

Closed
leaysgur wants to merge 1 commit intomainfrom
01-13-fix_oxfmt_use_tokio_stdin_out_to_handle_wouldblock_error
Closed

fix(oxfmt): Use tokio::stdin/out to handle WouldBlock error#17946
leaysgur wants to merge 1 commit intomainfrom
01-13-fix_oxfmt_use_tokio_stdin_out_to_handle_wouldblock_error

Conversation

@leaysgur
Copy link
Member

@leaysgur leaysgur commented Jan 13, 2026

Fixes #17939, closes #17943


Node.js sets stdout/stderr to non-blocking mode. When oxfmt is called via napi and writes large output using Rust's std::io::stdout(), it fails with WouldBlock error because std I/O expects blocking mode.

To fix, use tokio's async I/O which properly handles non-blocking I/O by retrying on WouldBlock.

Copilot AI review requested due to automatic review settings January 13, 2026 03:50
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-bug Category - Bug labels Jan 13, 2026
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

Copilot AI left a comment

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 refactors oxfmt to use async I/O with tokio for stdout/stderr operations to handle WouldBlock errors that can occur during pipe operations. The main changes involve converting synchronous print functions to async versions using tokio's I/O primitives.

Changes:

  • Converted run() methods in FormatRunner and StdinRunner to async functions
  • Replaced synchronous print_and_flush() with async print_stdout() and print_stderr() functions using tokio I/O
  • Restructured FormatRunner::run() to properly handle the async/sync boundary with DiagnosticService

Reviewed changes

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

Show a summary per file
File Description
apps/oxfmt/Cargo.toml Added tokio "io-util" and "io-std" features to support async I/O operations
apps/oxfmt/src/core/utils.rs Replaced synchronous print_and_flush() with async print functions using tokio I/O primitives
apps/oxfmt/src/stdin/mod.rs Converted StdinRunner::run() to async and updated to use new async print functions
apps/oxfmt/src/cli/format.rs Converted FormatRunner::run() to async, restructured to collect diagnostic output before async I/O operations
apps/oxfmt/src/main.rs Added await for async FormatRunner::run() call
apps/oxfmt/src/main_napi.rs Added await for async StdinRunner::run() and FormatRunner::run() calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Dunqing

This comment was marked as resolved.

graphite-app bot pushed a commit that referenced this pull request Jan 13, 2026
@leaysgur leaysgur closed this Jan 13, 2026
@leaysgur leaysgur deleted the 01-13-fix_oxfmt_use_tokio_stdin_out_to_handle_wouldblock_error branch January 13, 2026 05:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

oxfmt: Large files truncated when using --stdin-filepath option

3 participants