Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google cloud function not handling sigint

I have been working with google cloud functions for a while. There was never any issue with the error handling but lately, when I stop google cloud function on the localhost it gives out the following error.

^CReceived SIGINT
Received SIGINT
^CReceived SIGINT
Received SIGTERM
^CReceived SIGINT

After some time I find out that the program is still executing once the execution is complete the following errors arise.

Error: Process exited with code 0
    at process.<anonymous> (/Applications/XAMPP/xamppfiles/htdocs/web-dev/firestore-scripts/node_modules/@google-cloud/functions-framework/build/src/invoker.js:396:29)
    at process.emit (events.js:310:20)
    at process.EventEmitter.emit (domain.js:482:12)
    at process.exit (internal/process/per_thread.js:166:15)
    at Server.<anonymous> (/Applications/XAMPP/xamppfiles/htdocs/web-dev/firestore-scripts/node_modules/@google-cloud/functions-framework/build/src/invoker.js:402:29)
    at Object.onceWrapper (events.js:416:28)
    at Server.emit (events.js:322:22)
    at Server.EventEmitter.emit (domain.js:482:12)
    at emitCloseNT (net.js:1657:8)
    at processTicksAndRejections (internal/process/task_queues.js:83:21)

Well clearly I want my program to stop once I press ctrl + c but it doesn't.

I have added a SIGINT event listener and also added a try-catch to handle errors and send responses to clients for any kind of error. It is still not working.

For now, I'm manually killing off the current process which is not ideal to do.

Any help appreciated.

like image 757
Rahul Bharati Avatar asked Jun 22 '20 07:06

Rahul Bharati


2 Answers

Yeah, this is dumb. I don't have a solution, but my workaround is:

  • Ctrl+C
  • Hit the URL from the browser

For some reason this kills it.

like image 152
Zack Jordan Avatar answered Nov 15 '22 00:11

Zack Jordan


I think it is related to the Life Cycle of the local Cloud Functions implementation.

When a caller sends an HTTP request to the web server, the framework must take unmarshalling steps according to the developer's specified function signature type. The function must then be invoked by passing appropriate arguments conforming to the developer's specified function signature type.

When the function signals that it has completed executing (i.e., "completion signalling"), the framework must respond to the caller. Depending on the developer's function signature type, the framework may first need to marshall objects returned by the developer's function into an HTTP response.

What I'm thinking is that the Cloud Function is still running when you try to stop your program or maybe the connection with the caller has not been closed.

A wild guess is that when performing the Zack's steps the Function tries to connect again to the web server but SIGNINT is prioritized, making the program to completely stop.

What caught my attention is that you mentioned that this is a recent behavior. I would suggest to contact GCP support directly to perform a deeper inspection. You can also create a Public Issue Tracker. This could help to determine if this indeed is related to the life cycle of the function or if the function is getting stuck, etc.

like image 37
Kevin Quinzel Avatar answered Nov 14 '22 22:11

Kevin Quinzel