Skip to content

Commit 1d4269c

Browse files
fix(cluster-engine): skip side effects when lock acquisition fails
1 parent 6868882 commit 1d4269c

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

‎packages/socket.io-cluster-engine/lib/engine.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ export abstract class ClusterEngine extends Server {
213213
},
214214
});
215215

216+
if (!success) {
217+
break;
218+
}
219+
216220
switch (transportName) {
217221
case "polling": {
218222
if (message.data.type === "read") {

‎packages/socket.io-cluster-engine/test/in-memory.test.ts‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,27 @@ describe("in-memory", () => {
161161
it("should acquire read lock (different process)", async () => {
162162
const sid = await handshake(ports[0]);
163163

164-
const controller = new AbortController();
165-
const fetchPromise = fetch(url(ports[0], sid), {
166-
signal: controller.signal,
167-
}).catch(() => {});
164+
// acquire lock
165+
const fetchPromise = fetch(url(ports[0], sid));
166+
167+
{
168+
// check that the SID is locked for reading
169+
const res = await fetch(url(ports[1], sid));
170+
assert.equal(res.status, 400);
171+
// @ts-expect-error protected property
172+
assert.equal(engine2.clients[sid], undefined);
173+
}
168174

169-
const res = await fetch(url(ports[1], sid));
170-
assert.equal(res.status, 400);
175+
{
176+
// check that the lock works
177+
// @ts-expect-error protected property
178+
engine1.clients[sid]!.send("hello");
171179

172-
controller.abort();
173-
await fetchPromise;
180+
const res = await fetchPromise;
181+
const body = await res.text();
182+
183+
assert.equal(body, "4hello");
184+
}
174185
});
175186

176187
it("should acquire read lock (same process)", async () => {

0 commit comments

Comments
 (0)