-
Notifications
You must be signed in to change notification settings - Fork 16
Adds abort signal to requests #368
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
base: master
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #368 +/- ##
===========================================
+ Coverage 99.75% 100.00% +0.24%
===========================================
Files 11 11
Lines 404 434 +30
Branches 56 61 +5
===========================================
+ Hits 403 434 +31
+ Misses 1 0 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Enables request abortion using AbortSignal in all transports. The change ensures requests can be cancelled, prevents memory leaks and improves user experience by rejecting requests that are no longer relevant. Implements AbortError class to differentiate RPC errors from aborts. Ran `npm i baseline-browser-mapping@latest -D` to update browser mappings, and `npm audit fix` to fix 3 vulnerabilities (1 low, 1 moderate, 1 high).
|
Thanks for the PR !! Going to leave this here, early haven't fully reviewed the PR, but I'd say a few off the top of my head comments.
I'll comment further when I get a chance to go over it more in depth hopefully sometime this or early next week |
|
Installing baseline is to get rid of that
It's just a couple more tests to complete missing coverage, nothing else. |
| >; | ||
|
|
||
| export interface TransportOptions { | ||
| timeout?: number | null; |
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.
I think we don't have to move timeout into this object right now. Maybe we shouldn't as we'd introduce a breaking change as you mentioned as well. I'll ponder it for a short spell.
This is also because we might want to store more information in it. I think @shanejonas was at one point thinking about places to store/add more context to the request. I think that's also partially why there's this kind of tension to call it context vs. options. Maybe he can weigh in more on the naming here :D .
Maybe that's misleading in some way?
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.
Is it a breaking change? Does anyone actually provide their own transports?
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.
It's used out in the wild here's an example https://github.com/MetaMask/casper-js-sdk/blob/6628031d6f6fc1279e6748f4722263f724cd2511/src/services/ProviderTransport.ts#L2
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.
I think the solution suggested works well , and we can then streamline it later.
| * myClient.request({method: "foo", params: ["bar"]}).then(() => console.log('foobar')); | ||
| */ | ||
| public async request(requestObject: RequestArguments, timeout?: number) { | ||
| public async request(requestObject: RequestArguments, options?: Options | number) { |
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.
I think this makes sense then we can start to slowly phase out the number as a arg
zcstarr
left a comment
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.
I think overall it looks good just some adjustments with timing intervals, I think would make testing more reliable with a bigger window for timing jitter.
The only other thing here is a different name maybe than options, my only beef with just options is that it might be too generic, and it'd be nice to scope what can go into options or should go there. I'll give it a little more thought, I'm open to leaving it options want to here if maybe @shanejonas has any alternate ideas
| ); | ||
| expect(result).toEqual("bar"); | ||
| await new Promise((resolve) => setTimeout(resolve, 100)); | ||
| await new Promise((resolve) => setTimeout(resolve, 10)); |
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.
I'd keep these at 100 and reset the timeout to be 1000ms . I think this will make sure that slower machines don't catch event loop timing issues.
| internalID: 0, | ||
| }, | ||
| 10000, | ||
| { timeout: 100 }, |
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.
I'd maybe bump this to 1000 there's a significant potential for lag/jitter if I recall about post message window transport at least 1000 seems safer and maybe the timeouts that are set to bump back up to 100.
| // eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
| ): Promise<any> { | ||
| let prom = this.transportRequestManager.addRequest(data, timeout); | ||
| const timeout = options?.timeout ?? 5000; |
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.
null here should set the timeout to be null, here it seems like we'll always return 5000 , undefined defaults to 5000
| const timeout = options?.timeout ?? 5000; | |
| const timeout = options?.timeout === undefined ? 5000 : options.timeout; |
| return Promise.resolve(); | ||
| } | ||
| return this.addReq(data.internalID, timeout); | ||
| return this.addReq(data.internalID, timeout || null, signal); |
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.
I'm not sure this makes total sense here, timeout || null , I think it's not necessary as timeout can be number or null and the private method addReq handles the timeout
| >; | ||
|
|
||
| export interface TransportOptions { | ||
| timeout?: number | null; |
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.
It's used out in the wild here's an example https://github.com/MetaMask/casper-js-sdk/blob/6628031d6f6fc1279e6748f4722263f724cd2511/src/services/ProviderTransport.ts#L2
| >; | ||
|
|
||
| export interface TransportOptions { | ||
| timeout?: number | null; |
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.
I think the solution suggested works well , and we can then streamline it later.
Fixes #367
AbortErrorto differentiate RPC errors from aborts.npm i baseline-browser-mapping@latest -Dto update browser mappings (fixes warnings when running tests)npm audit fixto fix 3 vulnerabilities (1 low, 1 moderate, 1 high).fetcheris missing, and a test to coverindex.tsexports.