Skip to content

Commit

Permalink
update patches
Browse files Browse the repository at this point in the history
  • Loading branch information
mfornos committed Dec 12, 2024
1 parent d1f9cac commit dc11c7c
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .yarn/patches/@polkadot-api-ws-provider-npm-0.3.6-39c80167fe.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
diff --git a/dist/node/esm/node.mjs b/dist/node/esm/node.mjs
index 8707f2d1ba22e2f249330c7e59ed039237d4d7b9..d7352d6561977c758cfc69d76c8a7d4bb940e8b5 100644
--- a/dist/node/esm/node.mjs
+++ b/dist/node/esm/node.mjs
@@ -2,10 +2,32 @@ import { WebSocket } from 'ws';
import { getInternalWsProvider } from './ws-provider.mjs';
export { WsEvent } from './types.mjs';

+const PING_TIMEOUT = 45_000;
+
class WS extends WebSocket {
close() {
this.terminate();
}
+ // Triggers "close" on network failure
+ // (e.g. when pulling the cord, datacenter network infra migrations, &c.)
+ stayAlive() {
+ function heartbeat() {
+ clearTimeout(this.pingTimeout);
+
+ // Use `WebSocket#terminate()`, which immediately destroys the connection,
+ // instead of `WebSocket#close()`, which waits for the close timer.
+ // Safe assumption of 45 seconds ping frequency + latency.
+ this.pingTimeout = setTimeout(() => {
+ console.warn(`Terminate: ping timeout (${PING_TIMEOUT/1_000}s)`);
+ this.terminate();
+ }, PING_TIMEOUT);
+ }
+
+ this.on('ping', heartbeat);
+ this.on('close', function clear() {
+ clearTimeout(this.pingTimeout);
+ });
+ }
}
const getWsProvider = getInternalWsProvider(
WS
diff --git a/dist/node/esm/ws-provider.mjs b/dist/node/esm/ws-provider.mjs
index 867316423225f21bd35ed3e2fc60ff330dd20ec3..61a065fd1bbbbcc3de603d3f73efeaf2efdfc004 100644
--- a/dist/node/esm/ws-provider.mjs
+++ b/dist/node/esm/ws-provider.mjs
@@ -40,6 +40,7 @@ const getInternalWsProvider = (WebsocketClass) => {
const [uri, protocols] = switchTo || endpoints[idx++ % endpoints.length];
switchTo = null;
const socket = new WebsocketClass(uri, protocols);
+ socket.stayAlive && socket.stayAlive();
const forceSocketClose = () => {
try {
socket.addEventListener("error", noop, { once: true });
@@ -71,7 +72,8 @@ const getInternalWsProvider = (WebsocketClass) => {
event: e
}
);
- setTimeout(reject, e ? 300 : 0, e);
+ // don't retry too fast
+ setTimeout(reject, 5_000, e);
};
const timeoutToken = timeout !== Infinity ? setTimeout(() => {
initialCleanup();
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"typescript": "^5.6.3"
},
"resolutions": {
"@polkadot-api/observable-client@npm:0.6.2": "patch:@polkadot-api/observable-client@npm%3A0.6.2#~/.yarn/patches/@polkadot-api-observable-client-npm-0.6.2-ed0dacca53.patch"
"@polkadot-api/observable-client@npm:0.6.2": "patch:@polkadot-api/observable-client@npm%3A0.6.2#~/.yarn/patches/@polkadot-api-observable-client-npm-0.6.2-ed0dacca53.patch",
"@polkadot-api/ws-provider@npm:0.3.6": "patch:@polkadot-api/ws-provider@npm%3A0.3.6#~/.yarn/patches/@polkadot-api-ws-provider-npm-0.3.6-39c80167fe.patch"
},
"stableVersion": "2.3.2"
}
11 changes: 11 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,17 @@ __metadata:
languageName: node
linkType: hard

"@polkadot-api/ws-provider@patch:@polkadot-api/ws-provider@npm%3A0.3.6#~/.yarn/patches/@polkadot-api-ws-provider-npm-0.3.6-39c80167fe.patch":
version: 0.3.6
resolution: "@polkadot-api/ws-provider@patch:@polkadot-api/ws-provider@npm%3A0.3.6#~/.yarn/patches/@polkadot-api-ws-provider-npm-0.3.6-39c80167fe.patch::version=0.3.6&hash=9d1b4c"
dependencies:
"@polkadot-api/json-rpc-provider": "npm:0.0.4"
"@polkadot-api/json-rpc-provider-proxy": "npm:0.2.4"
ws: "npm:^8.18.0"
checksum: 10c0/8d1c2d5302e447155c654ba73bf885a6165d043ee0410ae8ef0494adacccc7db8c6cd5436714dd67d2ac479a4db474341d642b748b1b8d95f09281d3127e495f
languageName: node
linkType: hard

"@redis/bloom@npm:1.2.0":
version: 1.2.0
resolution: "@redis/bloom@npm:1.2.0"
Expand Down

0 comments on commit dc11c7c

Please sign in to comment.