-
Notifications
You must be signed in to change notification settings - Fork 17
Solve promise+event+memory leaks when the network fails #427
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
Conversation
…work fails before a response is received
Codecov Report
@@ Coverage Diff @@
## 6-dev #427 +/- ##
==========================================
+ Coverage 96.41% 96.45% +0.03%
==========================================
Files 32 33 +1
Lines 1535 1550 +15
==========================================
+ Hits 1480 1495 +15
Misses 55 55
Continue to review full report at Codecov.
|
test/protocol/common.test.js
Outdated
sinon = require('sinon'), | ||
KuzzleError = require('../../src/KuzzleError'), | ||
AbstractWrapper = require('../../src/protocols/abstract/common'); | ||
KuzzleError = require(`${root}/src/KuzzleError`), |
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.
This kind of shortcut beak editor ability to automatically refactor imports when renaming files
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 wouldn't know, I don't use IDEs 😑
I'll revert that one, since this makes code marginally more readable.
# [6.2.0](https://github.com/kuzzleio/sdk-javascript/releases/tag/6.2.0) (2019-07-31) #### Bug fixes - [ [#428](#428) ] Properly handle boolean flags in HTTP querystrings ([scottinet](https://github.com/scottinet)) - [ [#427](#427) ] Solve promise+event+memory leaks when the network fails ([scottinet](https://github.com/scottinet)) - [ [#424](#424) ] Prevent pending request leak when disconnect the SDK ([Aschen](https://github.com/Aschen)) - [ [#422](#422) ] Fix bug when decoding JWT in browser ([Aschen](https://github.com/Aschen)) - [ [#420](#420) ] Fix http protocol unresolved promise on connection error ([Aschen](https://github.com/Aschen)) #### New features - [ [#419](#419) ] Add bulk:write and bulk:mWrite ([Aschen](https://github.com/Aschen)) #### Enhancements - [ [#421](#421) ] Get api routes from server:publicApi ([Aschen](https://github.com/Aschen)) - [ [#423](#423) ] Emit queryError event on malformed request ([Aschen](https://github.com/Aschen)) - [ [#417](#417) ] Security controller documentation ([benoitvidis](https://github.com/benoitvidis)) ---
Description
Whenever a request is sent through
AbstractProtocol.query
:When an API response is received, its requestId is used to invoke the one-time listener which, in turns, remove the entry from the pending requests map, and resolves/rejects the promise.
But nothing was ever done if the network fails, meaning that requests were created with no hope of ever receiving a corresponding response.
This leads to several leaks, and it will also block users awaiting for SDK methods that might never resolve their returned promise.
This PR fixes the problem by making sure that
AbstractProtocol.clear
gets called on network disconnections (expected or not), ensuring that the pending requests map is properly cleared.This PR also enhances the "clear" method by making it unregister the one-time event, and reject the corresponding promise, to make sure that no trace remains of the pending request.
This PR builds over #424 and fixes/enhances it.