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

Commit 56a79e1

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 f83b2db commit 56a79e1

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
@@ -275,6 +275,13 @@ Subscription.prototype.subscribe = function() {
275275
_this._resubscribe(err);
276276
}
277277
});
278+
279+
// just in case the provider reconnects silently, resubscribe over the new connection
280+
if (_this.options.requestManager.provider.once) {
281+
_this.options.requestManager.provider.once('connect', function () {
282+
_this._resubscribe();
283+
});
284+
}
278285
} else {
279286
_this._resubscribe(err);
280287
}
@@ -310,7 +317,9 @@ Subscription.prototype._resubscribe = function (err) {
310317
});
311318
}
312319

313-
this.emit('error', err);
320+
if (err) {
321+
this.emit('error', err);
322+
}
314323

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

0 commit comments

Comments
 (0)