-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Hold the dev backend listen socket in the granian supervisor #7114
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Keep the development backend port open while hot reload restarts the worker, so requests made during a reload wait for the new worker instead of being refused. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| """Tests for development backend launchers in ``reflex.utils.exec``.""" | ||
|
|
||
| import os | ||
| import socket | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
@@ -80,6 +81,55 @@ def serve(self): | |
| assert seen["value"] == "True" | ||
|
|
||
|
|
||
| def test_run_granian_backend_binds_listen_socket_in_supervisor( | ||
| tmp_path: Path, mocker: MockerFixture | ||
| ): | ||
| """The dev server holds the listen socket so requests queue across worker restarts.""" | ||
| mocker.patch.object( | ||
| exec_utils, | ||
| "get_dev_backend_reload_marker", | ||
| return_value=tmp_path / exec_utils.DEV_BACKEND_RELOAD_MARKER, | ||
| ) | ||
| mocker.patch.object( | ||
| exec_utils, "get_app_instance_from_file", return_value="app:app" | ||
| ) | ||
| mocker.patch.object(exec_utils, "get_reload_paths", return_value=[]) | ||
| granian_server = pytest.importorskip("granian.server") | ||
| servers: list[object] = [] | ||
|
|
||
| class FakeGranian: | ||
| def __init__(self, *_args, **_kwargs): | ||
| self.bind_addr = "127.0.0.1" | ||
| self.bind_port = 0 | ||
| self.backlog = 16 | ||
| servers.append(self) | ||
|
|
||
| def on_reload(self, _callback): | ||
| pass | ||
|
|
||
| def serve(self): | ||
| pass | ||
|
|
||
| mocker.patch.object(granian_server, "Server", FakeGranian) | ||
|
|
||
| exec_utils.run_granian_backend( | ||
| host="127.0.0.1", port=0, loglevel=exec_utils.LogLevel.INFO | ||
| ) | ||
|
|
||
| (server,) = servers | ||
| server._init_shared_socket() # pyright: ignore[reportAttributeAccessIssue] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This test runs entirely in one process and never simulates the supervisor→worker handoff or a reload restart, so it doesn't exercise the queuing-across-restart behavior the PR title and docstring claim to verify. It only shows that a locally bound socket, once Prompt for AI agents |
||
| listener: socket.socket = server._sso # pyright: ignore[reportAttributeAccessIssue] | ||
| try: | ||
| assert listener.get_inheritable() | ||
| # Once a worker calls listen the supervisor's descriptor keeps the | ||
| # socket listening, so connections queue while no worker accepts. | ||
| listener.listen() | ||
| with socket.create_connection(listener.getsockname(), timeout=1): | ||
| pass | ||
| finally: | ||
| listener.close() | ||
|
|
||
|
|
||
| def test_with_development_condition_sets_node_and_bun_options(): | ||
| """Both runtime option vars gain the development condition flag.""" | ||
| env = exec_utils._with_development_condition({}) | ||
|
|
||
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.
The fake
serve()is a no-op, and the test manually initializes and listens on the socket. It therefore does not exercise Granian's worker descriptor handoff or a real reload cycle. A regression that closes the supervisor descriptor during worker shutdown or fails to pass it to the replacement worker could still pass this test, so the intended hot-reload behavior lacks direct coverage.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!