Skip to content
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

Merged
merged 8 commits into from
May 20, 2019

Conversation

Aschen
Copy link
Contributor

@Aschen Aschen commented May 9, 2019

What does this PR do ?

Even with the disabled property set to false, 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?

  • Step 1 : Subscribe to realtime notification with MQTT disabled
  • Step 2 : When a notification arrive, you should'nt see an error message in the console

Other changes

  • Protocol init method now return a Promise
  • Rename Protocol.protocol property to Protocol.name

@Aschen Aschen self-assigned this May 9, 2019
@codecov
Copy link

codecov bot commented May 9, 2019

Codecov Report

Merging #1298 into 1-dev will decrease coverage by 0.01%.
The diff coverage is 97.56%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...pi/core/entrypoints/embedded/protocols/socketio.js 93.15% <100%> (+0.09%) ⬆️
lib/services/broker/index.js 100% <100%> (ø) ⬆️
lib/api/core/httpRouter/index.js 98.68% <100%> (ø) ⬆️
...i/core/entrypoints/embedded/protocols/websocket.js 93.07% <100%> (ø) ⬆️
...ib/api/core/entrypoints/embedded/protocols/mqtt.js 95.23% <100%> (+1.12%) ⬆️
lib/api/core/entrypoints/embedded/index.js 98.31% <90%> (-0.53%) ⬇️
...pi/core/entrypoints/embedded/protocols/protocol.js 82.35% <90.9%> (+2.35%) ⬆️
...ib/api/core/entrypoints/embedded/protocols/http.js 99.33% <97.87%> (-0.67%) ⬇️

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 bbe7042...0fa800a. Read the comment docs.

@codecov
Copy link

codecov bot commented May 9, 2019

Codecov Report

Merging #1298 into 1-dev will decrease coverage by 0.01%.
The diff coverage is 97.58%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
...pi/core/entrypoints/embedded/protocols/socketio.js 93.15% <100%> (+0.09%) ⬆️
lib/services/broker/index.js 100% <100%> (ø) ⬆️
lib/api/core/httpRouter/index.js 98.68% <100%> (ø) ⬆️
...i/core/entrypoints/embedded/protocols/websocket.js 93.07% <100%> (ø) ⬆️
...ib/api/core/entrypoints/embedded/protocols/mqtt.js 95.23% <100%> (+1.12%) ⬆️
lib/api/core/entrypoints/embedded/index.js 98.31% <90%> (-0.53%) ⬇️
...pi/core/entrypoints/embedded/protocols/protocol.js 82.35% <90.9%> (+2.35%) ⬆️
...ib/api/core/entrypoints/embedded/protocols/http.js 99.33% <97.91%> (-0.67%) ⬇️

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 363d1da...21c821c. Read the comment docs.

Copy link
Contributor

@scottinet scottinet left a 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}".`);
Copy link
Contributor

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');
Copy link
Contributor

@scottinet scottinet May 10, 2019

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.

Copy link
Contributor

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.

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 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);
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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);

@Aschen Aschen force-pushed the fix-disabled-protocol-init branch from 256cee0 to 3cf1a64 Compare May 10, 2019 11:56
@Aschen Aschen force-pushed the fix-disabled-protocol-init branch from 3cf1a64 to ae349dd Compare May 10, 2019 11:57

for (const protocol of Object.keys(this.protocols)) {
this.protocols[protocol].init(this);
for (const ProtocolClass of [
Copy link
Member

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?

Copy link
Contributor

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)

Copy link
Member

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 🙂

@alexandrebouthinon alexandrebouthinon merged commit 5e8dc8b into 1-dev May 20, 2019
@alexandrebouthinon alexandrebouthinon deleted the fix-disabled-protocol-init branch May 20, 2019 11:37
@Aschen Aschen mentioned this pull request Jun 14, 2019
Aschen added a commit that referenced this pull request Jun 14, 2019
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)
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.

4 participants