Skip to content

fix(redis-streams-emitter): add the leading slash to the namespace - #5648

Open
rafay247 wants to merge 1 commit into
socketio:mainfrom
rafay247:fix/redis-streams-emitter-of-leading-slash
Open

rafay247 wants to merge 1 commit into
socketio:mainfrom
rafay247:fix/redis-streams-emitter-of-leading-slash

Conversation

@rafay247

Copy link
Copy Markdown

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

Emitter.of() in @socket.io/redis-streams-emitter uses the namespace name as given. emitter.of("custom") publishes messages with nsp: "custom", but the server registers the namespace as "/custom" (io.of("custom") adds the slash). The adapter looks up namespaceToAdapters.get(message.nsp), finds nothing, and the message is silently dropped.

io.of() and the of() of @socket.io/postgres-emitter both add the leading slash.

New behavior

of() adds the leading slash when it is missing, with the same expression as @socket.io/postgres-emitter:

(nsp[0] !== "/" ? "/" : "") + nsp

Other information (e.g. related issues)

Added a test that broadcasts with emitter.of("custom") to clients connected to /custom. Without the change it times out, because no client receives the event. All 14 tests pass with both redis and ioredis (standalone Redis 7), and npm run format:check passes. I did not run the cluster and Valkey variants.

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