Skip to content

Commit de59809

Browse files
authored
fix: handle SIGINT in ErrorHandler (#126)
Currently, when running the Functions Framework in a Docker container by running `docker run`, one cannot stop the running container with Ctrl+C. This is because the Functions Framework doesn't handle SIGINT in the ErrorHandler. This change handles SIGINT in the similar fashion as SIGTERM i.e. close the web server and exit the process.
1 parent 36bf3eb commit de59809

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/invoker.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,12 @@ export class ErrorHandler {
535535
logAndSendError(new Error(`Process exited with code ${code}`), latestRes);
536536
});
537537

538-
process.on('SIGTERM', () => {
539-
this.server.close(() => {
540-
process.exit();
538+
['SIGINT', 'SIGTERM'].forEach(signal => {
539+
process.on(signal as NodeJS.Signals, () => {
540+
console.log(`Received ${signal}`);
541+
this.server.close(() => {
542+
process.exit();
543+
});
541544
});
542545
});
543546
}

0 commit comments

Comments
 (0)