-
Notifications
You must be signed in to change notification settings - Fork 5k
hot: reset process.stdin/stdout/stderr listeners on reload #30633
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
Open
robobun
wants to merge
16
commits into
main
Choose a base branch
from
farm/5f7289a3/hot-reload-stdin-listeners
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
edc65ba
hot: reset process.stdin/stdout/stderr listeners on reload
robobun 0e5484c
test: swallow stream-abort rejections from stdout/stderr readers
robobun 03e1d86
test: move --hot stdin listener test to its own file
robobun 01eced8
ci: retrigger
robobun 4ec1d0a
hot: satisfy exception-scope check after resetStdioForHotReload
robobun 3738562
hot: clear kDataListening/kFlowing when resetting stdin for reload
robobun c148f7a
hot: unpipe stdin on reset; make test tolerant of Windows watcher
robobun 1461ff9
build: retrigger gate (release build was transient resource failure)
robobun dcbbeec
hot: restore cooked TTY mode when resetting stdin for reload
robobun 240380c
hot: clear readline keypress-decoder state when resetting stdin
robobun 3eea72c
test: handle EOF-as-empty-read in the hot-stdin PTY driver
robobun 162b91c
test: kill the --hot child when the PTY driver is signalled
robobun 6a32d78
test: drop arbitrary sleep from the hot-stdin PTY driver
robobun 27807a8
hot: only delete readline's keypress-decoder marker on stdin reset
robobun 200b431
test: account for getStdinStream's internal end listener
robobun 667ee41
hot: check for an exception after resetStdioForHotReload instead of a…
robobun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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 file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/usr/bin/env python3 | ||
| # Drives `bun --hot <fixture>` inside a pseudo-terminal so readline runs in | ||
| # terminal mode (emitKeypressEvents + raw mode), types a line, rewrites the | ||
| # fixture to trigger a hot reload, then types another line. The test asserts | ||
| # on the child's stdout, which this script forwards verbatim. | ||
| import os | ||
| import pty | ||
| import re | ||
| import select | ||
| import signal | ||
| import sys | ||
| import time | ||
|
|
||
| command = sys.argv[1:] | ||
| fixture = sys.argv[-1] | ||
|
|
||
| master_fd, slave_fd = pty.openpty() | ||
| pid = os.fork() | ||
| if pid == 0: | ||
| os.close(master_fd) | ||
| os.setsid() | ||
| os.dup2(slave_fd, 0) | ||
| os.dup2(slave_fd, 1) | ||
| os.dup2(slave_fd, 2) | ||
| if slave_fd > 2: | ||
| os.close(slave_fd) | ||
| os.execvp(command[0], command) | ||
|
claude[bot] marked this conversation as resolved.
|
||
|
|
||
| os.close(slave_fd) | ||
| buffer = b"" | ||
|
|
||
|
|
||
| def wait_for(pattern, timeout=10): | ||
| global buffer | ||
| rx = re.compile(pattern.encode()) | ||
| deadline = time.time() + timeout | ||
| while time.time() < deadline: | ||
| if rx.search(buffer): | ||
| return True | ||
| ready = select.select([master_fd], [], [], 0.1)[0] | ||
| if ready: | ||
| try: | ||
| data = os.read(master_fd, 4096) | ||
| except OSError: | ||
| # Linux raises EIO once the child side of the PTY is closed. | ||
| break | ||
| if not data: | ||
| # macOS/BSD report EOF as an empty read instead; bail out so | ||
| # we don't spin on a closed fd until the deadline. | ||
| break | ||
| buffer += data | ||
| sys.stdout.buffer.write(data) | ||
| sys.stdout.buffer.flush() | ||
| return rx.search(buffer) is not None | ||
|
|
||
|
|
||
| def terminate_handler(signum, frame): | ||
| # The hand-rolled fork above does not give the child a controlling TTY, | ||
| # so closing the PTY master won't SIGHUP it. If we're torn down early | ||
| # (test-runner timeout sends SIGTERM, Ctrl+C sends SIGINT, or our own | ||
| # SIGALRM fires), kill the `bun --hot` child explicitly so it doesn't | ||
| # outlive the test. | ||
| print("PYTHON: terminated by signal %d" % signum, flush=True) | ||
| try: | ||
| os.kill(pid, 9) | ||
| except Exception: | ||
| pass | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| signal.signal(signal.SIGALRM, terminate_handler) | ||
| signal.signal(signal.SIGTERM, terminate_handler) | ||
| signal.signal(signal.SIGINT, terminate_handler) | ||
| signal.alarm(30) | ||
|
|
||
| ok = wait_for(r"READY 1 ") | ||
| os.write(master_fd, b"hello\r") | ||
| ok = wait_for(r"ECHO 1 hello") and ok | ||
|
|
||
| # Trigger a hot reload by rewriting the fixture in place. | ||
| with open(fixture) as f: | ||
| source = f.read() | ||
| with open(fixture, "w") as f: | ||
| f.write(source) | ||
|
|
||
| # READY 2 is printed after createInterface() has synchronously re-wired the | ||
| # data→keypress bridge, so it is safe to type immediately once it appears. | ||
| ok = wait_for(r"READY 2 ") and ok | ||
| os.write(master_fd, b"world\r") | ||
| # Wait for any ECHO of "world" (from whichever load) or time out. | ||
| wait_for(r"ECHO \d+ world", timeout=5) | ||
| # Drain a little longer so a duplicate echo (the pre-fix bug) is captured too. | ||
| wait_for(r"\x00nevermatches\x00", timeout=1) | ||
|
|
||
| print("PYTHON: done", flush=True) | ||
| try: | ||
| os.kill(pid, 9) | ||
| except Exception: | ||
| pass | ||
| os.waitpid(pid, 0) | ||
| sys.exit(0 if ok else 1) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.