Skip to content

fix: allow socketsJoin/socketsLeave/disconnectSockets to be awaited - #5581

Closed
Ankit-Silwal wants to merge 1 commit into
socketio:mainfrom
Ankit-Silwal:fix/awaitable-socketsJoin
Closed

Ankit-Silwal wants to merge 1 commit into
socketio:mainfrom
Ankit-Silwal:fix/awaitable-socketsJoin

Conversation

@Ankit-Silwal

Copy link
Copy Markdown

Summary

  • Updates Adapter.addSockets, delSockets, and disconnectSockets return types from void to void | Promise<void>
  • Updates BroadcastOperator.socketsJoin, socketsLeave, and disconnectSockets to propagate the adapter's return value
  • Updates RemoteSocket.join and leave return types accordingly

Context

This is the companion change for socketio/socket.io-redis-adapter#577, which makes the Redis adapter's addSockets/delSockets/disconnectSockets return Promises that resolve once all remote nodes have acknowledged the operation.

Without this change, the Promise returned by the Redis adapter is silently dropped because BroadcastOperator.socketsJoin doesn't return the adapter's result.

Usage

// Before: fire-and-forget, emit may miss remote sockets
io.in(socketId).socketsJoin(room);
io.to(room).emit('event', data);

// After: awaitable, guarantees all nodes have processed the join
await io.in(socketId).socketsJoin(room);
io.to(room).emit('event', data);

Fully backward compatible — the return type is void | Promise<void>, so existing code that doesn't await continues to work unchanged.

Related: #4734

Test plan

  • socket.io-adapter TypeScript compilation passes
  • Backward compatible — void | Promise<void> is a supertype of both void and Promise<void>
  • Integration test with Redis adapter to verify ordering

🤖 Generated with Claude Code

Update the return types of addSockets, delSockets, and
disconnectSockets in the base Adapter from void to void | Promise<void>
so adapters (like the Redis adapter) can return Promises that resolve
once all remote nodes have processed the operation.

Update BroadcastOperator's socketsJoin, socketsLeave, and
disconnectSockets to propagate the adapter's return value, enabling:
  await io.in(socketId).socketsJoin(room);

This is fully backward compatible — existing code that doesn't await
continues to work unchanged, while multi-server setups with async
adapters can now await to ensure ordering guarantees.

Related: #4734

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Ankit-Silwal Ankit-Silwal closed this by deleting the head repository Oct 27, 2026
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