-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_handleServerNotification on Connection.ts has an unhandled error. #3053
Comments
Subscribe errors are caught here: https://github.com/solana-labs/solana-web3.js/blob/maintenance/v1.x/src/connection.ts#L6255-L6270 Unsubscribe errors are caught here: https://github.com/solana-labs/solana-web3.js/blob/maintenance/v1.x/src/connection.ts#L6310-L6322 In neither place are these errors surfaced to your application. It's possible that a check for All things considered, this subscriptions API and implementation are terminally flawed. We've completely rewritten it in 2.0, and I encourage you to migrate your app now. https://x.com/anza_xyz/status/1819093864394764674 |
Yes, in fact that is the problem, but I don't know how to solve it. If the program arrives to the line where is written I have modified
I have tried three different things without success:
Case 2. Add it to
Case 3. Add this piece of code in lines
Running the test
Running
Adding a
I will test it over a real server because I don't have the knowledge to do the test. By the way I think lines 6.297-6.299 are repeated and can be deleted: Using a totaly refactored library means investing lots of hours in learning how it works (take into account that there are not many examples published to use as reference), for a big project may have sense, for an small one may be it is faster to do your own small library instead of trying to learn how such a complex one works (talking from my ignorant point of view). Thank you. |
This in not working fine in my code, it just gives back
But even in that case, this code:
prints: |
Hello,
I solved the problem months ago but I haven't had time to do it in the
right way (passing the test and pushing the code).
You are already involved with v2, and this was for version v1.95.5, so it
is not important any more.
There were two main problems from my point of view:
1. Websocket status gives problems, some errors in _rpcWebSocket.Call()
drives the lib to an infinite loop (see code below). So I exported
'readyState' as you suggested (rpc-websocket.ts attached) to handle
webSocket status in another way in "connection.ts".
// TODO: Maybe add an 'errored' state or a retry limit?
this._setSubscription(hash, {
...subscription,
state: 'subscribed',
});
2. The lib has a big reentrance loop for subscriptions on "connection.ts",
that drives to a stack or memory heap overflow.
If you have many subscriptions (i.e.: follow 50 tokens price/status
means having 200 subscriptions), every time something changes the app
checks 200 subscriptions, this becomes impossible to handle by the heap and
it finishes by crashing.
// it reviews all subscriptions every time each subscription changes
await Promise.all(Object.keys(this._subscriptionsByHash).map(async hash =>
{...all subscriptions reviewed in all status changes..})));
Instead of that I did it like this (one status machine for each
subscription):
// Review all subscriptions
await Promise.all(
Object.keys(this._subscriptionsByHash).map(async hash => {
return this.estatus_machine(hash);
}),
);
// Review all changes of each subscription isolated (it doesn't review
changes in one subscription because of a status change in another
subscription)
private async estatus_machine(hash:string){..}
Regards.
J. Pablo.
El mié, 7 ago 2024 a las 8:11, Steven Luscher ***@***.***>)
escribió:
… Subscribe errors are caught here:
https://github.com/solana-labs/solana-web3.js/blob/maintenance/v1.x/src/connection.ts#L6255-L6270
Unsubscribe errors are caught here:
https://github.com/solana-labs/solana-web3.js/blob/maintenance/v1.x/src/connection.ts#L6310-L6322
In neither place are these errors surfaced to your application.
It's possible that a check for readyState could be added to
isCurrentConnectionStillActive(). Could you try that, and send a PR if it
works?
All things considered, this subscriptions API and implementation are
terminally flawed. We've completely rewritten it in 2.0, and I encourage
you to migrate your app now.
https://x.com/anza_xyz/status/1819093864394764674
—
Reply to this email directly, view it on GitHub
<#3053 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAX7LQPYXCW3DWK5YQYYZXDZQG27TAVCNFSM6AAAAABL5KIX3WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENZSGY4TCOBZGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
My app uses connect.onAccountChange() and connect.removeAccountChangeListener() and is keeps open 100-200 subscritions.
Main libraries:
The app crashes when it tries to use subscribe/unsubscribe using onAccountChange()/removeAccountChangeListener() and the Websocket is not with readyState===1.
Fail when trying to subscribe (it goes in an infinite loop with all the accounts handled at that moment):
Fail when trying to unsubscribe (it goes in an infinite loop with all the accounts handled at that moment):
And finally crashes:
As far as WebSocket.readyState is not visible, I have tried to catch the error in different ways but I can't catch it.
Option 1: try-catch
Option 2: catch chained
These errors are in file "rpc-websocket.ts" call and notify reject funcions:
But I think the problem could came from 'connection.ts' which has this piece of code with a no controlled catch, because I can't catch the error:
Few questions open en Solana Stack Exchange:
https://solana.stackexchange.com/questions/15643/accountunsubscribe-and-accountsubscribe-error-tried-to-call-a-json-rpc-method-w
https://solana.stackexchange.com/questions/15698/solana-web3-js-it-is-not-possible-to-detect-websocket-error
Could it be a bug?
How can I handle or catch this error?
How can I check websocket.readyStatus to avoid subscribe/unsubscribe when it is not in OPEN or CONNECTING?
The text was updated successfully, but these errors were encountered: