gestalt-mobile 0.55.1 → 0.55.2

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.
@@ -8,7 +8,12 @@ import { isSlowClient } from '../../../platform/events/slow-client.js';
8
8
  import { installWebSocketHeartbeat } from '../../../platform/events/websocket-heartbeat.js';
9
9
  export function registerSessionEvents(app, deps) {
10
10
  const server = new WebSocketServer({ noServer: true });
11
+ let closing = false;
11
12
  app.server.on('upgrade', (request, socket, head) => {
13
+ if (closing) {
14
+ socket.destroy();
15
+ return;
16
+ }
12
17
  const url = new URL(request.url ?? '/', 'http://relay.invalid');
13
18
  const match = /^\/api\/sessions\/([^/]+)\/events$/.exec(url.pathname);
14
19
  const after = Number(url.searchParams.get('after') ?? '0');
@@ -79,5 +84,25 @@ export function registerSessionEvents(app, deps) {
79
84
  connection.on('close', cleanup);
80
85
  });
81
86
  });
82
- app.addHook('onClose', async () => server.close());
87
+ // HTTP shutdown waits for upgraded sockets, so onClose is too late to drain
88
+ // them. Bound the close handshake so an offline browser cannot block restart.
89
+ app.addHook('preClose', async () => {
90
+ closing = true;
91
+ await new Promise((resolve, reject) => {
92
+ const timeout = setTimeout(() => {
93
+ for (const connection of server.clients)
94
+ connection.terminate();
95
+ }, 1_000);
96
+ timeout.unref();
97
+ server.close((error) => {
98
+ clearTimeout(timeout);
99
+ if (error)
100
+ reject(error);
101
+ else
102
+ resolve();
103
+ });
104
+ for (const connection of server.clients)
105
+ connection.close(1012, 'service restart');
106
+ });
107
+ });
83
108
  }
@@ -48,7 +48,7 @@ export class ManagedUpgrade {
48
48
  throw new Error('A managed Mobile restart descriptor is required');
49
49
  }
50
50
  this.current = { instanceId: this.current.instanceId, phase: 'updating' };
51
- this.starting = this.run('gestalt', ['update-restart'], {
51
+ this.starting = this.run(this.environment.GESTALT_MANAGER_BIN || 'gestalt', ['update-restart'], {
52
52
  cwd: this.cwd,
53
53
  env: this.environment,
54
54
  timeout: 15_000,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gestalt-mobile",
3
- "version": "0.55.1",
3
+ "version": "0.55.2",
4
4
  "description": "Mobile-first web relay for durable Codex development sessions",
5
5
  "keywords": [
6
6
  "codex",