Unverified Commit 252c5a69 authored by Leah's avatar Leah Committed by GitHub

make stdout blocking on macos (#51883)

### What?

Node.js sets stdout to non-blocking by default, rust expects it to be blocking

so when logging a lot of data, it can happen that rust receives an error while writing causing it to panic, the error is just that the resource is temporarily unavailable, but rust doesn't handle this case

See https://github.com/napi-rs/napi-rs/issues/1630
parent 7dfa56c7
...@@ -276,6 +276,20 @@ const nextDev: CliCommand = async (argv) => { ...@@ -276,6 +276,20 @@ const nextDev: CliCommand = async (argv) => {
) )
} }
if (process.platform === 'darwin') {
// rust needs stdout to be blocking, otherwise it will throw an error (on macOS at least) when writing a lot of data (logs) to it
// see https://github.com/napi-rs/napi-rs/issues/1630
// and https://github.com/nodejs/node/blob/main/doc/api/process.md#a-note-on-process-io
if (process.stdout._handle != null) {
// @ts-ignore
process.stdout._handle.setBlocking(true)
}
if (process.stderr._handle != null) {
// @ts-ignore
process.stderr._handle.setBlocking(true)
}
}
let bindings: any = await loadBindings() let bindings: any = await loadBindings()
let server = bindings.turbo.startDev({ let server = bindings.turbo.startDev({
...devServerOptions, ...devServerOptions,
......
...@@ -2,6 +2,15 @@ ...@@ -2,6 +2,15 @@
// Extend the NodeJS namespace with Next.js-defined properties // Extend the NodeJS namespace with Next.js-defined properties
declare namespace NodeJS { declare namespace NodeJS {
// only for rust, see https://github.com/napi-rs/napi-rs/issues/1630
interface TTY {
setBlocking(blocking: boolean): void
}
interface WriteStream {
_handle?: TTY
}
interface Process { interface Process {
/** /**
* @deprecated Use `typeof window` instead * @deprecated Use `typeof window` instead
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment