-
Notifications
You must be signed in to change notification settings - Fork 1
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
Only create api promise once #249
Only create api promise once #249
Conversation
✅ Deploy Preview for pendulum-pay ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
await api.isReady; | ||
|
||
const currentSpecVersion = await getSpecVersion(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that we reload all metadata after a runtime upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
In other services we already have a caching mechanism in place. It's implemented with this class. Since we are only dealing with one network (pendulum) in the signer-service, I and don't need to cache the API per network, I think it's fine the way you implemented it.
Thanks @ebma, I didn't even check how we do it elsewhere. Just looking at the other code, they don't reconnect the api in case it becomes disconnected. I didn't expect this to work. I was just testing this case locally. Actually when the connection fails and you wait long enough, polkadot-js just crashes the complete app, so that it is forced to restart completely anyway. This is exactly not what I expect a library to do. 😱 So ignore my concern, the other codebases will work then. |
It does actually. In the testing-service, if you have a look here, the API is reconnected when a call fails (which might fail because the API is disconnected, or because the metadata is outdated, etc). The same logic is in the token-api here and in the faucet here.
That's crazy though, does it throw a specific error or how does it crash? |
True, I missed that.
The error is:
Having a closer look at this, it might not be polkadot-js to blame but we possibly just miss some proper catch blocks around any calls to the polkadotjs Api object, the way it is done in the other codebases. Anyway, an error thrown inside a handler of an express app should usually not crash the whole app but should be caught by express so that it will just respond with a 500 error. That's why it looks strange to me. |
Hmm okay, weird. I guess it's because of this timeout. It's 60 seconds by default but we can pass another one. Looking at this, every call we do is stored as a handler and these handlers are looped to check if any of them timed out. Seems like handlers are only created for each call to |
I realized that we configured the express server wrong and the error handler is not called properly so that the whole app crashes instead of returning a 500. I just fixed this in another PR. |
Closes #248
This solution avoids the memory leak and even after running for many requests, the heap will regularly be completely garbage collected.
However, I don't know whether this solution works reliably over a long time. I just tested locally and disconnected WIFI repeatedly and the service could successfully reconnect again. Unfortunately, I can't find any documentation for these functions.