-
Notifications
You must be signed in to change notification settings - Fork 127
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 disabled protocol initialization #1298
Conversation
Codecov Report
@@ Coverage Diff @@
## 1-dev #1298 +/- ##
==========================================
- Coverage 93.83% 93.82% -0.02%
==========================================
Files 98 98
Lines 6848 6865 +17
==========================================
+ Hits 6426 6441 +15
- Misses 422 424 +2
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## 1-dev #1298 +/- ##
==========================================
- Coverage 93.85% 93.83% -0.02%
==========================================
Files 98 98
Lines 6862 6879 +17
==========================================
+ Hits 6440 6455 +15
- Misses 422 424 +2
Continue to review full report at Codecov.
|
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.
Also, you have to unstage the package-lock file
@@ -191,6 +200,9 @@ class EmbeddedEntryPoint extends EntryPoint { | |||
}) | |||
.timeout(this.kuzzle.config.services.common.defaultInitTimeout) | |||
.then(() => { | |||
if (this.protocols[manifest.name]) { | |||
throw new KuzzleInternalError(`Conflicting protocol name "${manifest.name}".`); |
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.
Should be a PluginImplementationError
error
@@ -374,7 +382,7 @@ class HttpProtocol extends Protocol { | |||
}; | |||
|
|||
if (typeof allowCompression !== 'boolean') { | |||
throw new Error('Invalid HTTP "allowCompression" parameter value: expected a boolean value'); | |||
throw new KuzzleInternalError('Invalid HTTP "allowCompression" parameter value: expected a boolean value'); |
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.
(discussion - this doesn't block this PR)
No, this is not a Kuzzle internal error, but a configuration error (which is probably a lacking Error object).
This doesn't really matter because, in the end, the error is caught during initialization, and that aborts Kuzzle's start sequence. The error type is only really useful when a response is sent back to a client, or when it's a plugin error.
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.
Actually I opted for a different approach myself, while working on you-know-what: I'm using the assert
native module for checks made during startup.
It's cleaner as in most cases we expect failed assertions to stop the program execution at some point.
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 with the usage of assert
@@ -112,6 +136,11 @@ describe('lib/core/api/core/entrypoints/embedded/index', () => { | |||
error: sinon.spy() | |||
} | |||
}); | |||
|
|||
HttpMock.prototype.init = sinon.stub().resolves(true); |
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.
DRY: putting this.init = sinon.stub().resolves(true);
in the FakeProtocol constructor allows you to get rid of these lines
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.
No because I want to know separately when I call one of the init
function
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 don't understand: with my proposal, won't each class instance have its own init function?
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.
Since I am instantiating theses classes in the EmbeddedEntrypoint, I have to set the stub directly on the prototype if I want to be able to change the returned value (eg: MqttMock.prototype.init = sinon.stub().resolves(false);
)
it('should return false if the protocol is disabled', () => { | ||
entrypoint.config.protocols.mqtt.enabled = false; | ||
|
||
return protocol.init(entrypoint) |
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.
(nitpicking) can be simplified with fulfilledWith:
return should(protocol.init(entrypoint)).fulfilledWith(false);
256cee0
to
3cf1a64
Compare
3cf1a64
to
ae349dd
Compare
…le into fix-disabled-protocol-init
|
||
for (const protocol of Object.keys(this.protocols)) { | ||
this.protocols[protocol].init(this); | ||
for (const ProtocolClass of [ |
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.
Are you sure removing this.protocols
property does not break the custom protocols implementation capability?
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.protocols
is not removed
What this PR does is to go back to a previous state where only active embedded protocols are stored in that object (I changed that not that long ago, when even inactive protocols where stored)
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 tanks for those explanations 🙂
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)
What does this PR do ?
Even with the
disabled
property set tofalse
, the protocols are all loaded into memory.The footprint is small but I ran into a bug with realtime notification where Kuzzle try to send notification with the
dispatch
method even if the protocol was disabled.Now the protocols are initialized and if they are
disabled
Kuzzle does not keep them in memory.How should this be manually tested?
Other changes
init
method now return a PromiseProtocol.protocol
property toProtocol.name