Skip to content

Commit 6e6ebd1

Browse files
committed
fix(dynamodb-streams|kinesis|s3): fix unresolved promise blocking further serverless processes
1 parent db63659 commit 6e6ebd1

File tree

3 files changed

+41
-32
lines changed
  • packages

3 files changed

+41
-32
lines changed

packages/serverless-offline-dynamodb-streams/src/index.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ServerlessOfflineDynamodbStreams {
2929
this.hooks = {
3030
'offline:start:init': this.start.bind(this),
3131
'offline:start:ready': this.ready.bind(this),
32-
'offline:start': this._startWithExplicitEnd.bind(this),
32+
'offline:start': this._startWithReady.bind(this),
3333
'offline:start:end': this.end.bind(this)
3434
};
3535
}
@@ -56,24 +56,27 @@ class ServerlessOfflineDynamodbStreams {
5656
);
5757
}
5858

59-
async ready() {
59+
ready() {
6060
if (process.env.NODE_ENV !== 'test') {
61-
await this._listenForTermination();
61+
this._listenForTermination();
6262
}
6363
}
6464

65-
async _listenForTermination() {
66-
const command = await new Promise(resolve => {
67-
process.on('SIGINT', () => resolve('SIGINT')).on('SIGTERM', () => resolve('SIGTERM'));
68-
});
65+
_listenForTermination() {
66+
const signals = ['SIGINT', 'SIGTERM'];
67+
68+
signals.map(signal =>
69+
process.on(signal, async () => {
70+
this.serverless.cli.log(`Got ${signal} signal. Offline Halting...`);
6971

70-
this.serverless.cli.log(`Got ${command} signal. Offline Halting...`);
72+
await this.end();
73+
})
74+
);
7175
}
7276

7377
async _startWithExplicitEnd() {
7478
await this.start();
75-
await this.ready();
76-
this.end();
79+
this.ready();
7780
}
7881

7982
async end(skipExit) {

packages/serverless-offline-kinesis/src/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ServerlessOfflineKinesis {
2929
this.hooks = {
3030
'offline:start:init': this.start.bind(this),
3131
'offline:start:ready': this.ready.bind(this),
32-
'offline:start': this._startWithExplicitEnd.bind(this),
32+
'offline:start': this._startWithReady.bind(this),
3333
'offline:start:end': this.end.bind(this)
3434
};
3535
}
@@ -56,24 +56,27 @@ class ServerlessOfflineKinesis {
5656
);
5757
}
5858

59-
async ready() {
59+
ready() {
6060
if (process.env.NODE_ENV !== 'test') {
61-
await this._listenForTermination();
61+
this._listenForTermination();
6262
}
6363
}
6464

65-
async _listenForTermination() {
66-
const command = await new Promise(resolve => {
67-
process.on('SIGINT', () => resolve('SIGINT')).on('SIGTERM', () => resolve('SIGTERM'));
68-
});
65+
_listenForTermination() {
66+
const signals = ['SIGINT', 'SIGTERM'];
67+
68+
signals.map(signal =>
69+
process.on(signal, async () => {
70+
this.serverless.cli.log(`Got ${signal} signal. Offline Halting...`);
6971

70-
this.serverless.cli.log(`Got ${command} signal. Offline Halting...`);
72+
await this.end();
73+
})
74+
);
7175
}
7276

73-
async _startWithExplicitEnd() {
77+
async _startWithReady() {
7478
await this.start();
75-
await this.ready();
76-
this.end();
79+
this.ready();
7780
}
7881

7982
async end(skipExit) {

packages/serverless-offline-s3/src/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ServerlessOfflineS3 {
3030
this.hooks = {
3131
'offline:start:init': this.start.bind(this),
3232
'offline:start:ready': this.ready.bind(this),
33-
'offline:start': this._startWithExplicitEnd.bind(this),
33+
'offline:start': this._startWithReady.bind(this),
3434
'offline:start:end': this.end.bind(this)
3535
};
3636
}
@@ -57,24 +57,27 @@ class ServerlessOfflineS3 {
5757
);
5858
}
5959

60-
async ready() {
60+
ready() {
6161
if (process.env.NODE_ENV !== 'test') {
62-
await this._listenForTermination();
62+
this._listenForTermination();
6363
}
6464
}
6565

66-
async _listenForTermination() {
67-
const command = await new Promise(resolve => {
68-
process.on('SIGINT', () => resolve('SIGINT')).on('SIGTERM', () => resolve('SIGTERM'));
69-
});
66+
_listenForTermination() {
67+
const signals = ['SIGINT', 'SIGTERM'];
68+
69+
signals.map(signal =>
70+
process.on(signal, async () => {
71+
this.serverless.cli.log(`Got ${signal} signal. Offline Halting...`);
7072

71-
this.serverless.cli.log(`Got ${command} signal. Offline Halting...`);
73+
await this.end();
74+
})
75+
);
7276
}
7377

74-
async _startWithExplicitEnd() {
78+
async _startWithReady() {
7579
await this.start();
76-
await this.ready();
77-
this.end();
80+
this.ready();
7881
}
7982

8083
async end(skipExit) {

0 commit comments

Comments
 (0)