fix(socket): join only the ack room receipts are asked in

A socket listing events in auth.acks joined an ack room beside each of its
rooms and its own id. Receipts are only asked in the user's room, or the app's
for an app socket, so that is the one ack room it joins.
This commit is contained in:
Daniel Salazar committed 2026-10-29 17:46:15 -07:00
1 parent 7cc346d015
commit efba8bb7a9
2 files changed
+21 -5

No files matched your search

@@ -625,6 +625,24 @@ describe('SocketService (live socket.io)', () => {
await closeAll(userId, [other]);
});
it('joins only the ack room of the room it is asked in', async () => {
const userId = await userIdOf();
const socket = await connect({
auth_token: user.token,
acks: ['demo.ack'],
});
expect(
socketService.has({ room: ackRoom(String(userId), 'demo.ack') }),
).toBe(true);
for (const room of [accountSocketRoom(userId), socket.id!]) {
expect(
socketService.has({ room: ackRoom(room, 'demo.ack') }),
).toBe(false);
}
await closeAll(userId, [socket]);
});
it('hears nothing from a room nobody is in', async () => {
await expect(
socketService.askWithAck(
+3 -5
View File
@@ -681,13 +681,11 @@ export class SocketService extends PuterService {
// user.id is numeric in the DB; stringify for room name
// so adapter lookups key on a stable type.
const rooms = socketRoomsFor(decision.accept);
const acks = handshakeAcks(handshakeAuth?.acks);
// Asks go to the user's or the app's room, never the others.
socket.join([
...rooms,
...acks.flatMap((event) =>
[...rooms, socket.id].map((room) =>
ackRoom(room, event),
),
...handshakeAcks(handshakeAuth?.acks).map((event) =>
ackRoom(rooms[0], event),
),
]);
next();