-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Remove jl_getch()
to fix race condition in getpass()
#45954
Merged
staticfloat
merged 4 commits into
master
from
sf/goodnight_sweet_jl_getch_i_hardly_knew_thee
Jul 8, 2022
Merged
Remove jl_getch()
to fix race condition in getpass()
#45954
staticfloat
merged 4 commits into
master
from
sf/goodnight_sweet_jl_getch_i_hardly_knew_thee
Jul 8, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This should fix the intermittent testing failures seen in the following buildkite logs:
|
We accidentally introduced a race condition in `getpass()` by having `jl_getch()` toggle terminal modes for each keystroke. Not only is this slower and wasteful, it allows the kernel to receive keystrokes within a TTY in canonical mode (where it replaces certain characters [0]) and then reads from the kernel buffer in non-canonical mode. This results in us reading a `0x00` when we expected a `0x04` in certain cases on CI, which breaks some of our tests. The fix is to switch the TTY into raw mode once, before we ever print the password prompt, which closes the race condition. To do this, we moved more code from C to Julia, and removed the `jl_getch()` export, instead providing `jl_termios_size()`. [0] https://github.com/torvalds/linux/blob/e35e5b6f695d241ffb1d223207da58a1fbcdff4b/drivers/tty/n_tty.c#L1318
staticfloat
force-pushed
the
sf/goodnight_sweet_jl_getch_i_hardly_knew_thee
branch
from
July 6, 2022 21:04
0b37dbf
to
f93e1c8
Compare
vtjnash
reviewed
Jul 8, 2022
Co-authored-by: Jameson Nash <[email protected]>
vtjnash
reviewed
Jul 8, 2022
Co-authored-by: Jameson Nash <[email protected]>
vtjnash
reviewed
Jul 8, 2022
vtjnash
reviewed
Jul 8, 2022
Co-authored-by: Jameson Nash <[email protected]>
This was referenced Jul 10, 2022
ffucci
pushed a commit
to ffucci/julia
that referenced
this pull request
Aug 11, 2022
…5954) * Remove `jl_getch()` to fix race condition in `getpass()` We accidentally introduced a race condition in `getpass()` by having `jl_getch()` toggle terminal modes for each keystroke. Not only is this slower and wasteful, it allows the kernel to receive keystrokes within a TTY in canonical mode (where it replaces certain characters [0]) and then reads from the kernel buffer in non-canonical mode. This results in us reading a `0x00` when we expected a `0x04` in certain cases on CI, which breaks some of our tests. The fix is to switch the TTY into raw mode once, before we ever print the password prompt, which closes the race condition. To do this, we moved more code from C to Julia, and removed the `jl_getch()` export, instead providing `jl_termios_size()`. [0] https://github.com/torvalds/linux/blob/e35e5b6f695d241ffb1d223207da58a1fbcdff4b/drivers/tty/n_tty.c#L1318 * Update base/util.jl Co-authored-by: Jameson Nash <[email protected]> * Apply suggestions from code review Co-authored-by: Jameson Nash <[email protected]> * Apply suggestions from code review Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Jameson Nash <[email protected]>
pcjentsch
pushed a commit
to pcjentsch/julia
that referenced
this pull request
Aug 18, 2022
…5954) * Remove `jl_getch()` to fix race condition in `getpass()` We accidentally introduced a race condition in `getpass()` by having `jl_getch()` toggle terminal modes for each keystroke. Not only is this slower and wasteful, it allows the kernel to receive keystrokes within a TTY in canonical mode (where it replaces certain characters [0]) and then reads from the kernel buffer in non-canonical mode. This results in us reading a `0x00` when we expected a `0x04` in certain cases on CI, which breaks some of our tests. The fix is to switch the TTY into raw mode once, before we ever print the password prompt, which closes the race condition. To do this, we moved more code from C to Julia, and removed the `jl_getch()` export, instead providing `jl_termios_size()`. [0] https://github.com/torvalds/linux/blob/e35e5b6f695d241ffb1d223207da58a1fbcdff4b/drivers/tty/n_tty.c#L1318 * Update base/util.jl Co-authored-by: Jameson Nash <[email protected]> * Apply suggestions from code review Co-authored-by: Jameson Nash <[email protected]> * Apply suggestions from code review Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Jameson Nash <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We accidentally introduced a race condition in
getpass()
by havingjl_getch()
toggle terminal modes for each keystroke. Not only is thisslower and wasteful, it allows the kernel to receive keystrokes within a
TTY in canonical mode (where it replaces certain characters [0]) and
then reads from the kernel buffer in non-canonical mode. This results
in us reading a
0x00
when we expected a0x04
in certain cases on CI,which breaks some of our tests.
The fix is to switch the TTY into raw mode once, before we ever print
the password prompt, which closes the race condition. To do this, we
moved more code from C to Julia, and removed the
jl_getch()
export,instead providing
jl_termios_size()
.[0] https://github.com/torvalds/linux/blob/e35e5b6f695d241ffb1d223207da58a1fbcdff4b/drivers/tty/n_tty.c#L1318