Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 8103d28

Browse files
committed
Ensure resubscription is done on silent reconnects
If the provider silently recoonects and emits a new "connect" event, the subscriptions have to be set again over that new connection.
1 parent e6cd828 commit 8103d28

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

packages/web3-core-subscriptions/src/subscription.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ Subscription.prototype.subscribe = function() {
274274
_this._resubscribe(err);
275275
}
276276
});
277+
278+
// just in case the provider reconnects silently, resubscribe over the new connection
279+
if (_this.options.requestManager.provider.once) {
280+
_this.options.requestManager.provider.once('connect', function () {
281+
_this._resubscribe();
282+
});
283+
}
277284
} else {
278285
_this._resubscribe(err);
279286
}
@@ -309,7 +316,9 @@ Subscription.prototype._resubscribe = function (err) {
309316
});
310317
}
311318

312-
this.emit('error', err);
319+
if (err) {
320+
this.emit('error', err);
321+
}
313322

314323
// call the callback, last so that unsubscribe there won't affect the emit above
315324
this.callback(err, null, this);

0 commit comments

Comments
 (0)