-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix(compile): panic when compiled with --no-terminal flag #28823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This works towards fixing [#27730](denoland/deno#27730) and [#21091](denoland/deno#21091). An error is not handled when calling `op_is_terminal`. Ironically, this causes the application to panic when bootstrapping if there is no terminal in windows. This PR does not fully fix the issue yet, as there is a similar problem in deno's code base, see this [pull request](denoland/deno#28823).
Can some one please review this one? 🙏 Not sure if/who I should mention to get more eyes on it, or just have patience... |
// deno-lint-ignore prefer-primordials | ||
stdin.push(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed? Seems quite risky without any tests attached
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was needed because it used debugLog
somewhere in _streams.mjs
.
But that is not yet possible because the debug environment is not yet initialized which causes it to panic.
However, I will need to check again if this is needed because #28855 got merged.
I didn't understand what the line was for but looking at the Node API it is supposed to end the stream when you push null
. I am not entirely sure if this is needed, stdin
is normally not instantly ended.
I don't think it is needed to end the stream for compatibility reasons with Node, as I don't think there is a similar feature for node.
In case the stdin
stream does need to end, the push needs to be called after initializeDebugEnv(nodeDebug)
. To do that you would again have to check that the stream is a dummy stdin
.
deno/ext/node/polyfills/process.ts
Lines 999 to 1025 in 84b192e
const newStdin = initStdin(); | |
if (newStdin) { | |
stdin = process.stdin = newStdin; | |
} | |
// Replace stdout/stderr if they are not terminals | |
if (!io.stdout.isTerminal()) { | |
/** https://nodejs.org/api/process.html#process_process_stdout */ | |
stdout = process.stdout = createWritableStdioStream( | |
io.stdout, | |
"stdout", | |
); | |
} | |
if (!io.stderr.isTerminal()) { | |
/** https://nodejs.org/api/process.html#process_process_stderr */ | |
stderr = process.stderr = createWritableStdioStream( | |
io.stderr, | |
"stderr", | |
); | |
} | |
arch = arch_(); | |
platform = isWindows ? "win32" : Deno.build.os; | |
pid = Deno.pid; | |
initializeDebugEnv(nodeDebug); |
Let me first check if debugLog
is still called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change related to the issue in this PR? Can we just merge the other change in here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with David, it probably should be added in another PR (if it's needed at all)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was related to the issue before, as this was one of the points where it would panic when running without a terminal.
Just checked and it no longer calls debugLog
or at least no longer panics so this is not required anymore! 👍
@JasperVanEsveld thanks for the PR, is there a test we could add that exercises this change? |
@bartlomieju I tried to do this but the compiler tells me I tried something like this:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
@bartlomieju @dsherret #29144 does exactly that. |
This works towards fixing #27730 and #21091.
When compiled with the
--no-terminal
flag under windows there are some issues related to stdin, stdout and stderr.This pull request fixes the panic when during bootstrap the terminal type is requested.
Previously it would return the error if the terminal was not valid, instead it now returns UNKNOWN.
The dummy stdin that is than provided instantly pushes null for some reason.
However this tries to do a
debugLog
which is not possible yet, as we are still initiating.I don't see the use for this push, so I removed the line.
If it is needed for something please let me know.
This PR does not fully fix the issue yet, as there is a similar problem in deno_core's
isTerminal
op, see this pull request.