-
Notifications
You must be signed in to change notification settings - Fork 124
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
Fix promise leaks #1311
Fix promise leaks #1311
Conversation
…et-kuzzle-emit-events
…et-kuzzle-emit-events
Codecov Report
@@ Coverage Diff @@
## 1-dev #1311 +/- ##
=========================================
+ Coverage 93.79% 93.8% +<.01%
=========================================
Files 98 98
Lines 6967 6991 +24
=========================================
+ Hits 6535 6558 +23
- Misses 432 433 +1
Continue to review full report at Codecov.
|
.then(() => this.engine.createOrReplace(modifiedRequest)) | ||
.then(_response => { | ||
response = _response; | ||
return this.kuzzle.indexCache.add( |
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 didn't understand why it's needed to add the index and the collection to the cache 🤔
If they did not already exists, Kuzzle will have reject the request and if they exists, they are already in the cache (populated at startup or added when creating the collection)
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 didn't pay attention to that line, since it was already there. But now that you mention it, I can't find why this would be useful.
That line was added by a 3-years old PR and my best guess is that, at that time, it was useful to put in cache the indexes/collections created directly in ES while Kuzzle was running to prevent false negatives.
This is not useful anymore since the index cache now features a hotreload
mechanism.
So I'll remove it. Good catch 👍
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 agree we need to handle rejections issued by the notifier but I am a little concerned with 2 points:
- Waiting for the Promise chain to resolve will have an impact on Kuzzle response time. I understand Koncorde is fast and we let the protocols handle the final
dispatch
without waiting for it but still, we have to wait for quite a bunch of operations, including some possible pipes from plugins. - I will check but it is not very clear to me if we cover all the cases where the notifier could raise an error while being sure it won't eventually be sent to the end-user.
I did not think yet on how we can tackle these possible issues or whether they are acceptable or not. What do you think?
@benoitvidis > the first issue is not that straightforward: what kind of performances are we measuring?
I'm using the conditional here, because in fact, I couldn't see any impact when I ran our benchmarks. So these considerations are theoretical, as far as I can see at least, and that's probably because the real-time engine is a lot faster than, say, checking user rights. About the second issue: I'm not sure, but I think that we probably will have new errors appearing once the new Kuzzle version is released, because the warnings we got came from unhandled promise rejections. |
Re-reading my answer, I agree that there are unknows with this PR. Do you know how we could be a bit more sure of the outcomes? |
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.
OK, I had not thought about the back-pressure issue and the fact the benchmarks do not show any difference is a good news :)
## What does this PR do ? Fix notifier issue introduced by #1311 Kuzzle notifier is instanciated before the services are and `notifier.cache` and `storage` properties were set to `undefined`. ### How should this be manually tested? ``` bash features/run.sh ```
Release 1.8.0 Bug fixes [ #1311 ] Fix promise leaks (scottinet) [ #1298 ] Fix disabled protocol initialization (Aschen) [ #1297 ] Fix timeouts on plugin action returing the request (benoitvidis) [ #1288 ] Fix an error when trying a non-partial bulk update (scottinet) [ #1286 ] Allows bulk inserts on aliases (benoitvidis) [ #1282 ] Scan keys on redis cluster (benoitvidis) [ #1279 ] Users must be authenticated to use auth:logout (scottinet) New features [ #1315 ] Add the new Vault module to handle encrypted application secrets (Aschen) [ #1302 ] Add write and mWrite (Aschen) [ #1305 ] Add pipes & hooks wildcard event (thomasarbona) Enhancements [ #1318 ] Add a maximum ttl to auth:login (benoitvidis) [ #1301 ] Upgrade the WebSocket libraries (scottinet) [ #1308 ] Events triggering refactor (scottinet) [ #1300 ] Collection specifications methods cloisoned to a collection (thomasarbona) [ #1295 ] Improve validation error messages (benoitvidis) [ #1292 ] Throw an error when the realtime controller is invoked by plugin developers (benoitvidis) [ #1257 ] Add ability to define mapping policy for new fields (Aschen) [ #1291 ] Fix --help on subcommands (Yoann-Abbes) [ #1289 ] Handle ping/pong packets (scottinet) [ #1273 ] Fix incomplete access logs (scottinet) Others [ #1317 ] Add ps dependency to plugin-dev Docker image for pm2 (benoitvidis) [ #1312 ] Check that .kuzzlerc.sample is well-formed (scottinet) [ #1299 ] Add Kuzzle Nightly & Redis 3 and 4 test (alexandrebouthinon)
Description
The functions exposed by the
notifier
core generate many promises that are not awaited, and whose rejections might not be handled. And this is bad practice.But more than a bad practice, this is also a real issue because, well... hm... I'll let Node.js do the explaining:
That kind of warning doesn't look nice in Kuzzle's logs, not mentioning the potential issue this might cause if Node.js starts crashing on unhandled promise rejections.
How to test
Check the unit tests logs: no more warnings 🎉