Skip to content

bare websockets - #6932

Open
benedikt-bartscher wants to merge 112 commits into
reflex-dev:mainfrom
benedikt-bartscher:make-sio-optional
Open

benedikt-bartscher wants to merge 112 commits into
reflex-dev:mainfrom
benedikt-bartscher:make-sio-optional

Conversation

@benedikt-bartscher

@benedikt-bartscher benedikt-bartscher commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

saves ~11.6 KB gz / ~41 KB raw frontend size (a small js chunk replaces whole socketio)
dropped python deps: wsproto, simple-websocket, python-socketio, python-engineio, bidict
new benchmarks in test_event_transport.py show about 2x performance increase compared to socketio

also migrates AppHarness to granian for consistency. otherwise downstream tests using AppHarness still need uvicorn and wsproto/websockets

related reflex-dev/xy#513

Review in cubic

@codspeed

codspeed Bot commented Aug 22, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 19 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 146 untouched benchmarks
🆕 4 new benchmarks
⏩ 8 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_transport_inbound_socketio N/A 18.3 ms N/A
🆕 test_transport_inbound_websocket N/A 11.8 ms N/A
🆕 test_transport_outbound_socketio N/A 32.5 ms N/A
🆕 test_transport_outbound_websocket N/A 15.1 ms N/A

Comparing benedikt-bartscher:make-sio-optional (9906f85) with main (6f5c39c)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@greptile-apps

greptile-apps Bot commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · The PR still needs the previously reported oversized-event error loop fixed before merging.RetriggerView in GreptileConfidence Score: 4/5

[High impact] The PR changes the default event connection used by Reflex apps and adds channel traffic to it.

The PR still needs the previously reported oversized-event error loop fixed before merging.

Findings

  1. P1 Send errors repeat forever ▶

Summary

Switches the default event connection to plain WebSockets, adds channels with binary attachments, and keeps Socket.IO as an optional transport.

  • Reflex sends its default app events over a plain WebSocket.
  • Apps send named channel messages and binary data over the event socket.
  • AppHarness runs its backend with embedded Granian.
  • Server settings and optional extras now match the WebSocket transports.
  • Benchmarks measure event traffic over both supported protocols.
  • String CORS settings now list exact allowed origins.

Reviews (91) · Last reviewed commit: "Test in a browser that the session cooki..." · Reviewed by Greptile

Comment thread reflex/event_namespace.py Resolved
@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review August 22, 2026 22:09
@benedikt-bartscher
benedikt-bartscher requested a review from a team as a code owner August 22, 2026 22:09

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 19 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/event_namespace.py Resolved
Comment thread reflex/event_namespace.py Resolved
Comment thread reflex/utils/exec.py Resolved
Comment thread reflex/utils/exec.py Resolved
@benedikt-bartscher
benedikt-bartscher marked this pull request as draft August 22, 2026 22:27
…ace, awaited disconnect cleanup; revert server-wide ws_max_size
Comment thread reflex/event_namespace.py Resolved
@benedikt-bartscher
benedikt-bartscher marked this pull request as ready for review August 22, 2026 22:46

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 17 files

Requires human review: Auto-approval blocked because this review re-detected 1 unresolved issue already reported by Cubic.

Re-trigger cubic

Comment thread reflex/event_namespace.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread reflex/event_namespace.py Resolved
Comment thread reflex/event_namespace.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread reflex/event_namespace.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread reflex/testing.py Resolved
Comment thread reflex/utils/exec.py Resolved
Comment thread pyproject.toml Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 6 files (changes from recent commits).

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

Comment thread reflex/testing.py Resolved
Comment thread tests/units/test_testing.py Resolved

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread reflex/event_namespace.py Resolved
A frame that overflowed the send backlog was queued before the
connection closed, so the writer could still deliver a send reported
as a miss.
…g it

An app that replaced EventNamespace and overrode on_event saw every
event but the hydrate on connect. The boot event goes through on_event
again, re-raised while booting so a failure still refuses the connect,
and overriding on_event now warns in favor of handle_event, which runs
for every event on both transports.
@FarhanAliRaza FarhanAliRaza added the enhancement Anything you want improved label Nov 12, 2026 — with ChatGPT Codex Connector
@masenf masenf added the breaking Public API facing change considered for minor release bump pre-v1.0 label Nov 16, 2026
Comment thread tests/units/test_testing.py Resolved
The added tests checked fragments of errors, warnings and log output;
compare each in full, with session ids normalized to a placeholder and
the expected traceback output derived from the raised exception.
Capture the token-loss test's log on the reflex logger, so its check
still sees debug records when that logger has a level of its own.
The websocket library and frame size warnings were checked by fragment;
compare the captured records in full.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 8 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread tests/units/test_app.py Resolved
The app double's enqueue returned None, so in dev mode handle_event's
add_done_callback raised AttributeError on every inbound event and both
inbound benchmarks measured the failure policy instead of the transport.
It now returns a resolved future, like the EventFuture enqueue returns, and
every transport benchmark fails if anything was logged at error level.

Walltime, 100 inbound events: websocket 146 us -> 140 us, Socket.IO
318-324 us -> 313-317 us.
The error code and message for a hydrate over the backend's limit were
defined in both websocket.js and state.js. websocket.js now exports
HYDRATION_PAYLOAD_TOO_LARGE and hydrationTooLargeError(size, limit, unit),
which the socket.io path in state.js uses too; the messages are unchanged.
The state.js harness builds the error with the real helper and pins the
socket.io message exactly.
monkeypatch.setattr saves the old value through getattr, which for
reflex.app's lazy Socket.IO exports runs the module __getattr__; its
undo then stores the resolved class as a real module attribute. That
shadows __getattr__, so test_app_socketio_reexports_without_the_extra
failed whenever it ran after a namespace-replacing test (17 of 20
pytest-randomly seeds). Patch the module dict instead, which undo
restores exactly, and check after those tests that no Socket.IO name
is left behind.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file (changes from recent commits).

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

Comment thread tests/units/test_event_namespace.py Resolved
Port upstream's EventNamespace changes to the moved namespace modules, so
both transports get them. The X-Forwarded-For validation of reflex-dev#7880 runs in
build_static_router_data, with _is_port and _forwarded_client_ip next to
_trusted_forwarded_value; _clip moves there too for its debug line, and
reflex.app imports it back. The suppress_warnings parameter of reflex-dev#7921 is on
BaseEventNamespace.emit_update, and the awaited lost-and-found
subscription of reflex-dev#7938 runs in BaseEventNamespace.handle_connect.

The X-Forwarded-For tests move to tests/units/test_event_namespace.py.
The modify_state test of reflex-dev#7921 builds a WebsocketEventNamespace and reads
the warning from reflex.event_namespace, which logs it now.
The check ran as a test of its own, so it only caught a leak when the
random order put it after the tests that replace the namespace class.
Both tests now replace it through one fixture, which checks reflex.app
once its patch is undone.
A warning another logger emits during the test no longer fails them.
page.route_web_socket opens a held socket for the page right away. The
plain WebSocket sends its connect frame as soon as its socket opens, so
the frame carried the first route and was dropped before the test
navigated, and the session never opened. Socket.IO first waits for the
engine.io open packet, which the route held back.

An init script now keeps the event socket CONNECTING, as the page sees
it, until the test releases it, which holds both transports before the
connect request.
The 20-second session timeout only closed the socket. On a dead link the
browser fires onclose when its closing handshake times out, up to a
minute later, and until then no connect_error reached the event loop,
so it waited to retry. The timeout now tears the socket down and reports
the connect error itself.
_accepted_nodelay wrapped every fd in /dev/fd with socket.fromfd, which
dups the fd and leaks the copy when the fd is not a socket. One of them
was the write end of the multiprocessing resource tracker's pipe, started
earlier in the session by the echo server tests' spawned process. At
interpreter exit the tracker then never saw EOF, and CPython 3.12.16 and
3.14.4, whose ResourceTracker.__del__ waits for it without a timeout,
hung after pytest's summary until the job timed out. The scan now skips
fds that are not sockets.
# Conflicts:
#	packages/reflex-frontend/src/utils/state.js
#	packages/reflex-frontend/tests/public_api.test.js
#	pyi_hashes.json
#	pyproject.toml
#	reflex/app.py
#	tests/integration/tests_playwright/test_navigation_before_connect.py
#	tests/integration/tests_playwright/test_stateless_app.py
#	tests/units/compiler/state_js.test.mjs
#	tests/units/reflex_base/client_event_queue_runtime.mjs
#	tests/units/test_app.py
Comment on lines +870 to +874
if (exceedsMessageLimit(frame, limit)) {
// The backend closes the connection over an oversized frame, losing
// every update in flight with it; drop this one message instead.
report(oversizedEventError(data?.name ?? event, frame, limit));
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Send errors repeat forever

If the browser provides reportError, rejecting an oversized event calls window.onerror, which sends another event through this same size check. After navigation adds a query string large enough to exceed the limit, withRouterData copies that query into the error report too. The page then keeps building and rejecting error reports indefinitely.

Report send failures without feeding them back through the same socket, or prevent oversized frontend-error reports from reporting themselves.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Public API facing change considered for minor release bump pre-v1.0 documentation Improvements or additions to documentation enhancement Anything you want improved perf Performance-improving changes roadmap https://github.com/reflex-dev/reflex/issues/2727

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants