Skip to content

feat(socket.io-adapter): surface partial results on fetchSockets timeout - #5646

Open
yxshee wants to merge 1 commit into
socketio:mainfrom
yxshee:feat/adapter-fetch-sockets-partial-timeout
Open

yxshee wants to merge 1 commit into
socketio:mainfrom
yxshee:feat/adapter-fetch-sockets-partial-timeout

Conversation

@yxshee

@yxshee yxshee commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

When fetchSockets() times out in ClusterAdapter or ClusterAdapterWithHeartbeat because one or more cluster nodes failed to respond in time, the returned Promise rejects with a timeout Error and discards all local sockets and remote socket responses that were already received before the timeout.

New behavior

Following the same convention used by emitWithAck() and serverSideEmitWithAck():

  • Attach the partial socket responses collected before timeout to the rejected error as err.responses in both ClusterAdapter#fetchSockets() and ClusterAdapterWithHeartbeat#fetchSockets() (and safely guard opts.flags?.timeout).
  • In BroadcastOperator#fetchSockets(), wrap any remote socket entries in err.responses into RemoteSocket instances (while keeping local Socket instances as-is) before rethrowing the error, so callers catching a timeout error receive the same RemoteSocket interface (rooms as a Set, emit(), join(), etc.) as on normal resolution. Errors without an array err.responses are rethrown unchanged.
try {
  const sockets = await io.timeout(1000).fetchSockets();
} catch (err) {
  // partial sockets from local node + responding remote nodes:
  console.log(err.responses);
}

Other information (e.g. related issues)

Fixes #4995

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.

[adapter]: Add option to fetchSockets that returns results even if some nodes didn't respond

1 participant