Skip to content

Conversation

Aschen
Copy link
Contributor

@Aschen Aschen commented Jul 16, 2019

What does this PR do?

When a request is made to Kuzzle, we setup a once listener to handle the response. If a disconnection occur (manual with disconnect() or not), the listener are never freed.

This PR save the pending requests in a Map and when a disconnection occur, a discarded event is triggered for each requests and then the map is cleared.

Fix #356

Other changes

  • add .npmignore

@codecov
Copy link

codecov bot commented Jul 16, 2019

Codecov Report

Merging #424 into 6-dev will increase coverage by 0.02%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##            6-dev     #424      +/-   ##
==========================================
+ Coverage   96.31%   96.33%   +0.02%     
==========================================
  Files          32       32              
  Lines        1520     1529       +9     
==========================================
+ Hits         1464     1473       +9     
  Misses         56       56
Impacted Files Coverage Δ
src/protocols/abstract/common.js 91.11% <100%> (+2.22%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 877fc42...906655f. Read the comment docs.

@codecov
Copy link

codecov bot commented Jul 16, 2019

Codecov Report

Merging #424 into 6-dev will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##            6-dev     #424     +/-   ##
=========================================
+ Coverage   96.31%   96.41%   +0.1%     
=========================================
  Files          32       32             
  Lines        1520     1535     +15     
=========================================
+ Hits         1464     1480     +16     
+ Misses         56       55      -1
Impacted Files Coverage Δ
src/protocols/abstract/common.js 91.11% <100%> (+2.22%) ⬆️
src/controllers/bulk.js 100% <0%> (ø) ⬆️
src/core/Jwt.js 100% <0%> (+4.76%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 877fc42...b37610a. Read the comment docs.

* Emits an event for each discarded pending request.
*/
clear () {
for (const request of this._pendingRequests.values()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not forEach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to avoid forEach because it's error prone when dealing with promise. I could use it here but I prefer to stick to the same construct everywhere

@scottinet scottinet merged commit 4f2ab1a into 6-dev Jul 17, 2019
@scottinet scottinet deleted the 356-event-listener-leak branch July 17, 2019 15:31
@scottinet scottinet mentioned this pull request Jul 31, 2019
scottinet added a commit that referenced this pull request Jul 31, 2019
# [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))
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants