@zukhruf/election 0.8.73 → 0.8.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,7 +79,7 @@ await using term = await election.campaign({ timeout: Infinity, signal });
79
79
  - **The leader record.** The winner writes `<claimFile>.leader` beside `claimFile`, before its term begins. It holds the epoch of the term, the process id of the leader, the address of its pipe, and its `leaseDuration`. The winner first removes the socket file of the pipe that the old record names, which a killed leader leaves ([ADR 0005](./docs/adr/0005-the-leader-record-names-the-process-and-the-pipe-of-a-term.md)).
80
80
  - **The wait.** A candidate tries the claim. When another candidate holds it, the candidate reads the record, connects to the pipe, and waits. The close of the pipe tells it that the leader left, and it tries at once. A candidate under a healthy leader makes no try ([ADR 0007](./docs/adr/0007-a-candidate-waits-on-pushes-from-the-leaders-pipe-not-on-a-period.md)).
81
81
  - **A hung leader.** A candidate that hears no heartbeat for the `leaseDuration` of the record sends `SIGKILL` to the process of the record, but only while it holds that process's pipe open. The kernel frees the claim and closes the pipe, and the candidate tries. The kernel refuses the kill for a process of another user: then the candidate ends nothing, and it waits for the close until its `timeout`. A reader never ends its own process, in the same way ([ADR 0006](./docs/adr/0006-a-candidate-ends-a-leader-that-is-silent-past-the-lease-duration.md)).
82
- - **A new leader that does not serve its pipe yet.** A connect that gives `ENOENT` or `ECONNREFUSED` comes while a new leader starts, or under a published leader. The candidate waits a back-off and tries again: 25 ms first, then 1.6 times longer each time, with a jitter of ±20 %, at most 1000 ms.
82
+ - **A new leader that does not serve its pipe yet.** A connect that rejects with `NoServerError` of [`@zukhruf/pipes`](../pipes/README.md#errors) comes while a new leader starts, or under a published leader. On Linux it also comes when the leader closes its pipe during the connect (#5317). The candidate waits a back-off and tries again: 25 ms first, then 1.6 times longer each time, with a jitter of ±20 %, at most 1000 ms.
83
83
  - **An observer.** `election.observe()` returns a `LeaderObserver` for a process that does not campaign. It holds a connection to the leader's pipe and ends a silent leader as a candidate does. `observer.left` resolves `'closed'` when the leader left, `'ended'` when the observer ended it, and `'absent'` when no leader served a pipe. It rejects with any other error. Dispose it to close the connection; then `left` does not settle. Its connection and its deadline do not keep the process alive. One observer reads one term ([ADR 0009](./docs/adr/0009-a-process-that-does-not-campaign-observes-the-leader.md)).
84
84
  - `leaseDuration` is the longest silence, in milliseconds, that a candidate or an observer accepts from the leader. It defaults to 15000, as the `LeaseDuration` of Kubernetes. A reader uses the value in the record, so the leader decides it.
85
85
  - `heartbeatInterval` is the time between two heartbeats, in milliseconds. It defaults to a third of `leaseDuration`, as etcd's client sends a keepalive every TTL / 3. The name is etcd's `heartbeat-interval`.
@@ -93,7 +93,7 @@ await using term = await election.campaign({ timeout: Infinity, signal });
93
93
  A term is a lease on leadership. `Term` implements the `Lease` interface of [`@zukhruf/lease`](../lease/README.md), so a function that takes a `Lease` also takes a term. See the glossary of [leases](../lease/CONTEXT.md).
94
94
 
95
95
  - `term.epoch` is the number of the term. Each epoch is below 2^31.
96
- - `term.resign()` ends the term and gives the claim up. A second call waits for the first, and its options do nothing. `await using` resigns at the end of its scope. When the release fails, the claim is still freed, and `resign` rejects with the release's error. When the release or the record of `clean` fails and freeing the claim fails too, `resign` rejects with a `SuppressedError`: its `suppressed` is that step's error, and its `error` is the failure to free. After a loss, `resign` never rejects: a failure to free the claim has no caller to go to, so it is a process warning (`process.emitWarning`).
96
+ - `term.resign()` ends the term and gives the claim up. A second call waits for the first, and its options do nothing. `await using` resigns at the end of its scope. When the release fails, the claim is still freed, and `resign` rejects with the release's error. When the release or the record of `clean` fails and freeing the claim fails too, `resign` rejects with a `SuppressedError`: its `suppressed` is that step's error, and its `error` is the failure to free. After a loss, `resign` never rejects, and the term still ends: a failure to stop watching the claim or to free it has no caller to go to, so it is a process warning (`process.emitWarning`). When both fail, the warning is a `SuppressedError`: its `suppressed` is the failure to stop watching, and its `error` is the failure to free.
97
97
  - `term.resign({ clean: true })` records a clean shutdown for the next term, and then ends the term. Use it only when the leader leaves nothing for the next term to recover, for example no work in progress. A lost term records nothing, also with `clean`. When the record fails, the claim is freed, and `resign` rejects with that error. The socket lock store of `@zukhruf/mutex` resigns clean when no process holds a key ([its ADR 0018](../mutex/docs/adr/0018-the-next-leader-skips-the-grace-window-after-a-clean-shutdown.md)). `@zukhruf/single-flight` no longer records a clean shutdown, because its coordinator has no grace window to skip ([its ADR 0010](../single-flight/docs/adr/0010-a-leader-holds-a-kernel-lock-on-its-key-until-its-outcome-is-handed-over.md)).
98
98
  - `term.afterCleanShutdown` is `true` only when the term just before this one resigned clean. Then the new leader knows that it has nothing to recover. It is `false` after a crash, after a lost term, after a resign without `clean`, and for the first term.
99
99
  - `term.signal` aborts with `LeaseLostError` when the term is lost while its leader still runs. The `subject` of the error is `'leadership'`, and its `cause` is the reason of the backend. The signal does not abort when the leader resigns.
@@ -1 +1 @@
1
- {"version":3,"file":"leader-reader.d.ts","sourceRoot":"","sources":["../../src/sqlite/leader-reader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAO5C,uGAAuG;AACvG,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtC,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,qFAAqF;IACrF,GAAG,EAAE,OAAO,CAAC;IACb,iHAAiH;IACjH,MAAM,EAAE,WAAW,CAAC;CACrB;AAKD;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,CAa1B"}
1
+ {"version":3,"file":"leader-reader.d.ts","sourceRoot":"","sources":["../../src/sqlite/leader-reader.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAO5C,uGAAuG;AACvG,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,OAAO,CAAC;AAEtC,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,qFAAqF;IACrF,GAAG,EAAE,OAAO,CAAC;IACb,iHAAiH;IACjH,MAAM,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,CAe1B"}
@@ -1,10 +1,8 @@
1
1
  import { addAbortListener } from 'node:events';
2
2
  import { isErrno } from '@zukhruf/fs';
3
- import { PipeAddress } from '@zukhruf/pipes';
3
+ import { NoServerError, PipeAddress } from '@zukhruf/pipes';
4
4
  import { unrefed } from './leader-pipe.js';
5
5
  import { readLeaderRecord } from './leader-record.js';
6
- /** The connect fails because no process serves the pipe of the record, or the pipe is another user's (ADR 0007). */
7
- const ABSENT = ['ENOENT', 'ECONNREFUSED', 'EACCES'];
8
6
  /**
9
7
  * Reads the leader record, connects to its pipe once, and resolves when the
10
8
  * leader left. Resolves `'absent'` when no leader serves a pipe.
@@ -27,7 +25,8 @@ export async function readLeader(recordPath, options) {
27
25
  });
28
26
  }
29
27
  catch (error) {
30
- if (ABSENT.some((code) => isErrno(error, code)))
28
+ // No server listens on the pipe of the record, or the pipe is another user's (ADR 0007).
29
+ if (error instanceof NoServerError || isErrno(error, 'EACCES'))
31
30
  return 'absent';
32
31
  throw error;
33
32
  }
@@ -1 +1 @@
1
- {"version":3,"file":"leader-reader.js","sourceRoot":"","sources":["../../src/sqlite/leader-reader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAI/C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAqB,gBAAgB,EAAE,MAAM,o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,GAAG,OAAO,CAAC,IAAI,CAAC,CAYnD;IAED,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAErC;CAiDF"}
1
+ {"version":3,"file":"term.d.ts","sourceRoot":"","sources":["../src/term.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,KAAK,EAAmB,MAAM,gBAAgB,CAAC;AAE7D,4FAA4F;AAC5F,MAAM,WAAW,SAAS;IACxB,+EAA+E;IAC/E,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,KAAK,KAAK,IAAI,GAAG,UAAU,CAAC;IACjD;;;OAGG;IACH,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACrC,oEAAoE;IACpE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB,uDAAuD;IACvD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B;;;;OAIG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;GAKG;AACH,qBAAa,IAAK,YAAW,KAAK,EAAE,eAAe;;IACjD,qGAAqG;IACrG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IAQrC,YACE,EAAE,KAAK,EAAE,kBAAkB,EAAE,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAAC,EACzE,KAAK,EAAE,SAAS,EAMjB;IAED,mFAAmF;IACnF,IAAI,MAAM,IAAI,WAAW,CAExB;IAED;;;;;;;OAOG;IACG,MAAM,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAYnD;IAED,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,CAErC;CAmDF"}
package/dist/term.js CHANGED
@@ -87,20 +87,22 @@ export class Term {
87
87
  }
88
88
  /**
89
89
  * A lost claim is no longer this term's to give up: a release could undo
90
- * the next leader's claim. Only its resources are freed, and a loss has no
91
- * caller to report a failure to, so a failure to free them is a process
92
- * warning.
90
+ * the next leader's claim. It only stops watching and frees the claim's
91
+ * resources. A loss has no caller to report a failure to, so a failure of
92
+ * either step is a process warning, and the term still ends. When both
93
+ * fail, the warning is a `SuppressedError` of the failure to free over the
94
+ * failure to stop watching.
93
95
  */
94
96
  async #freeLost() {
95
97
  try {
98
+ await using freeing = new AsyncDisposableStack();
99
+ freeing.defer(() => this.#steps.close());
96
100
  this.#watching.dispose();
97
101
  }
98
- finally {
99
- await this.#steps.close().catch((error) => {
100
- process.emitWarning(Error.isError(error)
101
- ? error
102
- : new Error(String(error), { cause: error }));
103
- });
102
+ catch (error) {
103
+ process.emitWarning(Error.isError(error)
104
+ ? error
105
+ : new Error(String(error), { cause: error }));
104
106
  }
105
107
  }
106
108
  }
package/dist/term.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"term.js","sourceRoot":"","sources":["../src/term.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAc,eAAe,EAAE,MAAM,gBAAgB,CAAC;AA0B7D;;;;;GAKG;AACH,MAAM,OAAO,IAAI;IACf,qGAAqG;IAC5F,KAAK,CAAS;IACvB;;;;OAIG;IACM,kBAAkB,CAAU;IAC5B,MAAM,CAAY;IAClB,MAAM,GAAG,IAAI,eAAe,CAAC,YAAY,CAAC,CAAC;IACpD,gEAAgE;IACvD,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IAChC,MAAM,GAAG,IAAI,MAAM,EAAQ,CAAC;IAC5B,SAAS,GAAG,IAAI,eAAe,EAAE,CAAC;IAE3C,YACE,EAAE,KAAK,EAAE,kBAAkB,EAA8C,EACzE,KAAgB;QAEhB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,kBAAkB,GAA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E,CAAC,CAAC;YACzC,MAAM,KAAK,CAAC;QACd,CAAC;QACD,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,SAAS;QACb,IAAI,CAAC;YACH,YAAY,OAAO,GAAG,IAAI,oBAAoB,EAAE,CAAC;YACjD,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;YACzC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,WAAW,CACjB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;gBAClB,CAAC,CAAC,KAAK;gBACP,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAC/C,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zukhruf/election",
3
- "version": "0.8.73",
3
+ "version": "0.8.75",
4
4
  "description": "Elects a leader among candidates. Each term has a higher epoch and ends when the leader resigns or dies. Backends subclass one campaign. `SqliteElection` elects among processes of one host; candidates and observers end a leader whose pipe heartbeats stop.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,13 +40,13 @@
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
- "@zukhruf/async": "^0.8.73",
44
- "@zukhruf/fs": "^0.8.73",
45
- "@zukhruf/lease": "^0.8.73",
46
- "@zukhruf/pipes": "^0.8.73"
43
+ "@zukhruf/async": "^0.8.75",
44
+ "@zukhruf/fs": "^0.8.75",
45
+ "@zukhruf/lease": "^0.8.75",
46
+ "@zukhruf/pipes": "^0.8.75"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@sinonjs/fake-timers": "15.5.0",
50
- "@zukhruf/testing": "^0.8.73"
50
+ "@zukhruf/testing": "^0.8.75"
51
51
  }
52
52
  }