Skip to content

refactor(core): move remote request handling into core behind remote-adapter feature - #783

Open
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:refactor/move-remote-request-handling-to-core
Open

refactor(core): move remote request handling into core behind remote-adapter feature#783
LiamCarPer wants to merge 1 commit into
Totodore:mainfrom
LiamCarPer:refactor/move-remote-request-handling-to-core

Conversation

@LiamCarPer

Copy link
Copy Markdown
Contributor

Part of #727.

Motivation

The redis, postgres and mongodb adapters each implement the same request handling: a near identical recv_req dispatch plus the same recv_* handlers (broadcast, broadcast_with_ack, rooms, add/del sockets, fetch sockets, disconnect sockets), and the same get_res skeleton (channel setup, response filter, take/timeout).

Solution

Added a RemoteRequestHandler trait in socketioxide-core behind the existing remote-adapter feature flag, with default implementations of the dispatch and of all the handlers. Each adapter only implements:

Redis and mongodb keep a tiny wrapper that decodes the raw driver item and delegates, postgres calls the dispatch directly from its notification pipeline.

Also added insert_response_handler and wait_responses helpers covering the identical get_res channel setup, response type filter, take/timeout and handler cleanup.

Some tiny differences were normalized on purpose:

  • send_res now takes (req_id, req_origin) everywhere with the strictest bounds (T: Serialize + Debug + Send + 'static, future + Send + 'static), redis's inverted order is handled inside its impl
  • a request missing its options now warns and is skipped for all adapters (redis already did it, postgres and mongodb silently dropped it)
  • the loopback check is done in the shared dispatch
  • logs use the same style

The postgres get_res now also wraps the response stream in a DropStream, fixing a leak of response handler entries for rooms and fetch_sockets requests.

No behavior or wire-format change.

Tests

The existing adapter tests (fixture based, no real DB needed) cover every moved handler for the three adapters. Added 6 unit tests in core for the default dispatch: add/del sockets, heartbeat hook, loopback ignore, missing options, and the rooms / broadcast with ack responses.

…adapter feature

Moves the duplicated remote request handling from the redis, postgres and
mongodb adapters into socketioxide-core behind the existing remote-adapter
feature flag.

- RemoteRequestHandler trait with default implementations of recv_req and
  all the recv_* handlers (broadcast, broadcast_with_ack, rooms, add/del
  sockets, fetch sockets, disconnect sockets). Adapters only provide their
  local adapter, send_res and an optional recv_heartbeat hook.
- insert_response_handler/wait_responses helpers covering the get_res
  channel setup, response type filter, take/timeout and handler cleanup.

Some tiny differences were normalized on purpose: send_res now takes
(req_id, req_origin) everywhere with the strictest bounds, a request
without options warns and is skipped for all adapters, the loopback check
is done in the shared dispatch and logs use the same style.

The postgres adapter get_res now also wraps the response stream in a
DropStream, fixing a leak of response handler entries for rooms and fetch
sockets requests.

No behavior or wire-format change.

Closes Totodore#774
@codspeed-hq

codspeed-hq Bot commented Sep 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 87 untouched benchmarks


Comparing LiamCarPer:refactor/move-remote-request-handling-to-core (c8569d3) with main (9a10442)

Open in CodSpeed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant