@dokebi/websocket-hub 0.4.2 → 0.4.3

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/AI.md CHANGED
@@ -128,4 +128,4 @@ Without `--config` it reads the file `DOKEBI_CONFIG` names (the one the app read
128
128
  - `dokebi-hub-status` writes the cause of a Redis failure to stderr (the stdout JSON stays as it is).
129
129
  - Extension hooks for the hub are listed as candidates in [D-0064](https://git.nyx-zone.com/dokebi/framework/-/blob/main/docs/decisions/D-0064-extension-contract.md) §9; there is no extension class yet.
130
130
 
131
- Evidence: `examples/18-websocket-hub` (real TCP peers, leader handover), `examples/23-websocket`, `examples/25-playground`, `tests/status.test.ts` (status, nonces, the command), D-0024, D-0029, D-0034, D-0038, D-0057 (replacing the ACK and resend of D-0025 and D-0042).
131
+ Evidence: `tests/integration.test.ts` (real TCP peers, leader handover), `examples/23-websocket`, `examples/25-playground`, `tests/status.test.ts` (status, nonces, the command), D-0024, D-0029, D-0034, D-0038, D-0057 (replacing the ACK and resend of D-0025 and D-0042).
package/dist/index.js CHANGED
@@ -75,7 +75,7 @@ class HubRuntime {
75
75
  /** Factory input: `{ app, options? }`. Options default to `app.config['dokebi-websocket-hub']`. */
76
76
  export const createPlugin = definePlugin({
77
77
  name: 'dokebi-websocket-hub',
78
- version: '0.4.2',
78
+ version: '0.4.3',
79
79
  core: '^0.4.2',
80
80
  options: declaration,
81
81
  // local: nothing. cluster: Redis, and NATS only when natsConnection is set (D-0029).
package/dist/leader.js CHANGED
@@ -122,8 +122,15 @@ export class Leader {
122
122
  throw new HubError('STALE_LEADER');
123
123
  return now;
124
124
  }
125
- #queue(fn) {
126
- if (this.#pending >= this.options.maxPending) {
125
+ /**
126
+ * Runs `fn` after the requests before it. `maxPending` bounds what peers ask for (BUSY); the
127
+ * leader's `own` work — its lease tick, and removing a server whose socket closed — waits its
128
+ * turn whatever the queue holds: refused as BUSY it read as a lost lease, and the node stopped
129
+ * its leader and dropped every peer in the middle of the load (audit R9-g11-3). It is bounded
130
+ * by itself: one tick at a time (the node), one removal per peer socket (`maxOwners`).
131
+ */
132
+ #queue(fn, own = false) {
133
+ if (!own && this.#pending >= this.options.maxPending) {
127
134
  this.#throttle.log('debug', 'Hub leader queue full; request refused', 'BUSY', undefined, {
128
135
  pending: this.#pending,
129
136
  });
@@ -187,7 +194,7 @@ export class Leader {
187
194
  void this.#queue(async () => {
188
195
  await this.#renew();
189
196
  await this.#remove(peer.owner, peer.session);
190
- }).catch((error) => {
197
+ }, true).catch((error) => {
191
198
  // Lease lost or Redis down: another server takes over and expires the owner.
192
199
  this.logger.log('error', 'Hub leader could not remove a disconnected server', {
193
200
  code: 'OWNER_REMOVE_FAILED',
@@ -691,7 +698,7 @@ export class Leader {
691
698
  return this.#queue(async () => {
692
699
  const now = await this.#renew();
693
700
  await this.#expire(now);
694
- });
701
+ }, true);
695
702
  }
696
703
  async stop() {
697
704
  if (this.#active)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dokebi/websocket-hub",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "WebSocket hub for Dokebi: connection roster, rooms, broadcast and kick across workers and servers.",
5
5
  "keywords": [
6
6
  "dokebi",
@@ -48,7 +48,7 @@
48
48
  "@dokebi/redis": "^0.4.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@dokebi/nats": "0.4.1",
51
+ "@dokebi/nats": "0.4.2",
52
52
  "@dokebi/redis": "0.4.1"
53
53
  },
54
54
  "dokebi": {