-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Description
What I’m seeing
When I use @socket.io/redis-streams-adapter with ioredis, the server receives events from clients, but emits to rooms (within a namespace) often don’t reach clients.
If I switch to the classic @socket.io/redis-adapter, everything works immediately with the same code.
I’m currently running only one Socket.IO server process locally (no sticky sessions / no load balancer).
Versions
socket.io:4.8.3@socket.io/redis-streams-adapter:^0.2.3ioredis:^5.9.2
Server setup
import http from "http";
import { Server } from "socket.io";
import { createAdapter } from "@socket.io/redis-streams-adapter";
import { Redis } from "ioredis";
const server = http.createServer();
const redis = new Redis({
host: process.env.REDIS_HOST, // redis-*****.europe-west3-1.gce.cloud.redislabs.com
port: Number(process.env.REDIS_PORT), // e.g. 16937
username: process.env.REDIS_USER || "default",
password: process.env.REDIS_PASS,
});
const io = new Server(server, {
path: "/v1/api/socket.io",
cors: { origin: "*" },
adapter: createAdapter(redis),
});
io.of("/chatbot").on("connection", (socket) => {
socket.on("join", async ({ customerId }) => {
await socket.join(customerId);
socket.emit("joined", { customerId });
});
socket.on("visitor-message", ({ customerId, message }) => {
// ✅ server receives this event
console.log("received visitor-message", { customerId, message });
// ❌ these emits do NOT reach clients when redis-streams-adapter is enabled
io.of("/chatbot").to(customerId).emit("visitor-message-broadcast", { customerId, message });
io.of("/dashboard").to("shop:demo").emit("visitor-message-broadcast", { customerId, message });
});
});
io.of("/dashboard").on("connection", (socket) => {
socket.on("join", async ({ shop }) => {
await socket.join(`shop:${shop}`);
socket.emit("joined", { shop });
});
});
server.listen(3000, () => console.log("listening on :3000"));Expected behavior
- After a socket joins a room,
namespace.to(room).emit(...)should deliver events to all clients in that room. - This should work in a single-node setup too.
Actual behavior
- Server receives events, but the room emits above don’t arrive at clients (same namespace + cross-namespace).
- Replacing the adapter with
@socket.io/redis-adaptermakes everything work.
Possibly related: CORS error only when using redis-streams-adapter
When using the streams adapter, I also sometimes see this in the browser:
Access to XMLHttpRequest at 'https://.../v1/api/socket.io/?EIO=4&transport=polling...'
from origin 'https://...' has been blocked by CORS policy:
No 'Access-Control-Allow-Origin' header is present on the requested resource.Not sure if this is a separate issue, but it only appeared while testing with redis-streams-adapter.
Additional note
I also tried to make redis-streams-adapter work with node-redis, but when I enabled the adapter, my HTTP server stopped responding (I might have misconfigured it). Switching to ioredis allowed the server to run, but emits still don’t work as described above. Switching to the classic Redis adapter works immediately.