Skip to content

Commit

Permalink
Release 2.14.12 - Fix realtime:shutdown event race condition (#2184)
Browse files Browse the repository at this point in the history
## Release 2.14.12

Fix a race condition on the `core:realtime:shutdown` event being used before module initialization and answerer registration
  • Loading branch information
Aschen authored Nov 2, 2021
1 parent 8244888 commit b057e8f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/core/realtime/hotelClerk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export class HotelClerk {
/**
* Clear the hotel clerk and properly disconnect connections.
*/
global.kuzzle.onAsk('core:realtime:shutdown', () => this.clearConnections());
global.kuzzle.on('kuzzle:shutdown', () => this.clearConnections());

/**
* Clear subscriptions when a connection is dropped
Expand Down
9 changes: 4 additions & 5 deletions lib/kuzzle/kuzzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,14 @@ class Kuzzle extends KuzzleEventEmitter {
this._state = kuzzleStateEnum.SHUTTING_DOWN;

this.log.info('Initiating shutdown...');
await this.pipe('kuzzle:shutdown');

// @deprecated
this.emit('core:shutdown');

// Ask the network layer to stop accepting new request
this.entryPoint.dispatch('shutdown');

await this.ask('core:realtime:shutdown');
await this.pipe('kuzzle:shutdown');

// @deprecated
this.emit('core:shutdown');

while (this.funnel.remainingRequests !== 0) {
this.log.info(`[shutdown] Waiting: ${this.funnel.remainingRequests} remaining requests`);
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kuzzle",
"author": "The Kuzzle Team <[email protected]>",
"version": "2.14.11",
"version": "2.14.12",
"description": "Kuzzle is an open-source solution that handles all the data management through a secured API, with a large choice of protocols.",
"bin": {
"kuzzle": "bin/start-kuzzle-server"
Expand Down
4 changes: 2 additions & 2 deletions test/core/realtime/hotelClerk/hotelClerk.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('HotelClerk', () => {
it('should have been registered with the "core:realtime:shutdown" event', async () => {
sinon.stub(hotelClerk, 'clearConnections').resolves();

kuzzle.ask.restore();
await kuzzle.ask('core:realtime:shutdown');
kuzzle.pipe.restore();
await kuzzle.pipe('kuzzle:shutdown');

should(hotelClerk.clearConnections).be.calledOnce();
});
Expand Down
2 changes: 0 additions & 2 deletions test/kuzzle/kuzzle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,6 @@ describe('/lib/kuzzle/kuzzle.js', () => {
should(kuzzle.pipe).calledWith('kuzzle:shutdown');
should(Bluebird.delay.callCount).approximately(5, 1);

should(kuzzle.ask).be.calledWith('core:realtime:shutdown');

// @deprecated
should(kuzzle.emit).calledWith('core:shutdown');

Expand Down

0 comments on commit b057e8f

Please sign in to comment.