akanjs 2.4.2-rc.3 → 2.4.2-rc.4
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/local/apps/serverLifecycle/serverLifecycle-local.db +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local.db-shm +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local.db-wal +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local_solid.db +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local_solid.db-shm +0 -0
- package/local/apps/serverLifecycle/serverLifecycle-local_solid.db-wal +0 -0
- package/package.json +1 -1
- package/server/akanApp.ts +15 -2
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/server/akanApp.ts
CHANGED
|
@@ -43,6 +43,19 @@ type GatewayUpstream = {
|
|
|
43
43
|
ws?: Extract<AkanUpstream, { type: "tcp" }>;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
+
/**
|
|
47
|
+
* Received-only close codes cannot be sent in a close frame. The gateway deliberately normalizes
|
|
48
|
+
* every unsendable code, including semantically distinct 1005 and 1006 events, to 1001 in both
|
|
49
|
+
* relay directions. In particular, Bun's global client `WebSocket.close()` throws an
|
|
50
|
+
* InvalidAccessError for these codes at the client-to-upstream relay; normalization at the
|
|
51
|
+
* upstream-to-client `Bun.ServerWebSocket.close()` relay is defensive and keeps behavior symmetric.
|
|
52
|
+
*/
|
|
53
|
+
const relayableCloseCode = (code: number): number => {
|
|
54
|
+
if (code >= 3000 && code <= 4999) return code;
|
|
55
|
+
if (code >= 1000 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006) return code;
|
|
56
|
+
return 1001;
|
|
57
|
+
};
|
|
58
|
+
|
|
46
59
|
/** Options for the Akan gateway that launches child server replicas and listens for traffic. */
|
|
47
60
|
export interface AkanAppOptions {
|
|
48
61
|
replica?: number | string;
|
|
@@ -583,7 +596,7 @@ export class AkanApp {
|
|
|
583
596
|
const result = ws.send(event.data as string | ArrayBuffer);
|
|
584
597
|
if (result === 0) upstream.close();
|
|
585
598
|
});
|
|
586
|
-
upstream.addEventListener("close", (event) => ws.close(event.code, event.reason));
|
|
599
|
+
upstream.addEventListener("close", (event) => ws.close(relayableCloseCode(event.code), event.reason));
|
|
587
600
|
upstream.addEventListener("error", () => ws.close(1011, "upstream websocket error"));
|
|
588
601
|
Object.assign(ws.data, { pending });
|
|
589
602
|
}
|
|
@@ -604,7 +617,7 @@ export class AkanApp {
|
|
|
604
617
|
}
|
|
605
618
|
|
|
606
619
|
#handleWsClose(ws: Bun.ServerWebSocket<GatewayWsData>, code: number, reason: string) {
|
|
607
|
-
ws.data.upstream.close(code, reason);
|
|
620
|
+
ws.data.upstream.close(relayableCloseCode(code), reason);
|
|
608
621
|
const child = this.#children.get(ws.data.childIdx);
|
|
609
622
|
if (child) child.metrics.activeWebSockets = Math.max(0, (child.metrics.activeWebSockets ?? 1) - 1);
|
|
610
623
|
}
|