cluster: a runner that lost its shard lock can still write replies and messages for that shard
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- postgresql, typescript
- Ambito
- databases, distributed-systems
Direzione di ricerca
Start with SqlMessageStorage and SqlRunnerStorage in effect/cluster, then read the shard reset and write paths named in the issue: resetShards, saveReply, saveRequest, saveEnvelope, clearReplies and clearAddress. Run the linked repro against the current code to confirm stale writes after lock loss. Done means shard writes from an old owner are rejected after a new owner resets the shard, while client writes without a fence still work.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Base: effect 4.0.6 (effect/cluster, SqlMessageStorage + SqlRunnerStorage on PostgreSQL advisory locks). main has the same code.
What happens. Shard ownership is a session advisory lock. A runner checks it every shardLockRefreshInterval.
Between two checks, the runner can lose the lock (its lock session ended, or it was paused) while another runner
acquires the shard, runs resetShards, and starts the same entities. The old runner does not know yet. Its handlers
finish and call saveReply, saveRequest, saveEnvelope, clearReplies and clearAddress. None of these check
who owns the shard, so the writes succeed.
Results:
- A persisted request gets two replies, or the old owner's reply wins over the new owner's.
- A
clearRepliesorclearAddressfrom the old owner deletes what the new owner just wrote. - With a duplicate primary key, the write is deduplicated with no error, so nobody sees it.
Repro (two runners believe they own one shard):
const cluster = yield* make({ backend: "pg", entities: HoldEntityLayer }) // persisted RPC that waits on a gate
const [stale] = yield* cluster.start(1)
const reply = yield* client("held").Hold(new Request({ id: "fenced" })).pipe(Effect.forkChild)
// handler has started on `stale`
yield* cluster.freeze(stale) // stale stops refreshing
yield* cluster.dropLockSessions // pg_terminate_backend on its lock session
const [owner] = yield* cluster.start(1) // owner acquires the shard and re-runs the request
assert(stale.sharding.hasShardId(shard)) // stale still believes it owns it
openGate(stale) // stale's handler finishes first
// 4.0.6: stale's reply is stored and returned to the caller.
// Expected: stale's saveReply fails; only owner's reply is stored.
Expected. Each shard acquisition gets an epoch. Every write on behalf of a shard carries the epoch the writer
acquired with, and storage rejects it in the same transaction if the shard's epoch has moved on. The rejection is a
typed error, logged at Error, and the entity on the stale runner stops.
Proposed fix (implemented on a fork, PR available).
SqlMessageStoragemigration0004_shard_epochsadds<prefix>_shards (shard_id, epoch).resetShardsraises the epoch of each shard it resets and returns aShardFenceper shard.MessageStorage.CurrentShardFencecarries the fence to the write.saveRequest,saveEnvelope,saveReply,
clearRepliesandclearAddressread the shard's epoch with a shared row lock (FOR SHARE,LOCK IN SHARE MODE,
HOLDLOCK) inside the write's transaction, and fail withShardFencedif it differs.resetShardstakes the
exclusive lock on the same row, so a stale write either commits before the new owner's reset or fails.- Writes by a client (sending to a shard it does not own) carry no fence and are not checked.
- An entity whose reply is fenced is stopped.
Shardingreleases a shard whose reset fails.
Runnable repro (real runner processes, fails on 4.0.6 and on main at 837e906): https://github.com/heyimcarlos/effect-cluster-repro, issue 3 in the README table.
- Lingua principale
- TypeScript
- Stelle
- 16.7k
- Fork
- 808
- Merge medio
- 11h 3m
- PR unite (30g)
- 840
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di Effect-TS/effect
-
PgClient: withTransaction dies instead of failing with SqlError when the server ends the sessionForse già presa @effect-bot l’ha presa oggi. Aperta
Effect-TS/effect#10290 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
shorthand for mapping over tagged union schemaForse già presa @effect-bot l’ha presa oggi. Apertaenhancement
Effect-TS/effect#10286 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Cluster: A way to remove processed requests from storageForse già presa @effect-bot l’ha presa 2 giorni fa. Apertaenhancement
Effect-TS/effect#10239 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 47/100
I maintainer di solito rispondono entro 1 giorno
-
`fromJsonSchemaDocument`: import open `patternProperties`Forse già presa @effect-bot l’ha presa 5 giorni fa. Aperta
Effect-TS/effect#10048 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di Effect-TS/effect
Issue simili
-
area: cli bug flake ready-for-agent
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
gazetta-studio/gazetta-studio#1772 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
microsoft/playwright#43875 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
documentation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
feature
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
calagopus/panel#285 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno