Skip to content

Commit 45de275

Browse files
authored
Merge pull request #30 from hackmdio/fix/incorrect-persistence-leader-check
fix/incorrect persistence leader aquire check
2 parents be0a26a + cdc04ed commit 45de275

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/y-socket-io/y-socket-io.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,10 +859,13 @@ export class YSocketIO {
859859
assert(this.client)
860860
const redis = this.client.redis
861861
const key = this.getLeaderKeyOf(namespace)
862-
const ok = await redis.set(key, this.serverId, {
862+
const prevVal = await redis.set(key, this.serverId, {
863863
NX: true,
864-
PX: PERSIST_LEADER_HEARTBEAT_INTERVAL
864+
PX: PERSIST_LEADER_HEARTBEAT_INTERVAL,
865+
GET: true
865866
})
867+
868+
const ok = prevVal === this.serverId || prevVal === null
866869
if (!ok) return false
867870

868871
this.persistentLeaderOf.add(namespace)

0 commit comments

Comments
 (0)