Back

shutdown event node

  • 0
  • Self Hosted
  • Functions
  • Databases
nev-21
12 Jun, 2023, 12:35

So I think the only way is calling an api that make the integration

TL;DR
Summary: The user is experiencing issues with the shutdown event node in their open-runtimes project. They have created a PR and received feedback. There is a discussion about how Docker sends signals and the node function not receiving them. There is a suggestion for a workaround using pm2-runtime inside Docker. There is a mention of a potential code addition to handle custom termination life-cycle. The user is unable to get any signal to catch and is experiencing issues with their code not running. There is a suggestion to create a feature request for the issue. In the end, it is suggested to call an API to make the integration work. Solution:
Binyamin
12 Jun, 2023, 12:42

For now, yes.

Binyamin
12 Jun, 2023, 12:42

You can create a feature request for it, as it sounds like there going to be some use-cases - like yours - when it's heplful.

nev-21
12 Jun, 2023, 12:43

Great, i will create it

Drake
12 Jun, 2023, 14:37

you should try it out 😉

nev-21
12 Jun, 2023, 15:18

Hi @Steven I don't understand you?

Drake
12 Jun, 2023, 16:14

process.on('SIGTERM', async () => .....) but it doesn't work.

What happened when you did this?

nev-21
12 Jun, 2023, 16:15

It doesnt run the code, I tried to debug creating a document in an appwrite collection but it doesnt create it

Drake
12 Jun, 2023, 16:45

nvm..ya i can't get any signal to catch

Binyamin
12 Jun, 2023, 16:45

I've just tested it with all kind of stop process, and same..

Drake
12 Jun, 2023, 16:45

i'm not sure if it's docker and how we're starting nodemon or im using the wrong signal 🤷🏼‍♂️

Binyamin
12 Jun, 2023, 16:46

Yes, this also what I've seen that it depends on how the Node (pm2) is running and what how the process is being terminated.

Binyamin
12 Jun, 2023, 16:48

It sounds like it can be added here https://github.com/utopia-php/orchestration/blob/main/src/Orchestration/Adapter/DockerCLI.php#L437

Something like this.

TypeScript
...
        Console::execute("docker exec {$name} strat-termination"
        $result = Console::execute("docker rm " . ($force ? '--force': '') . " {$name}", '', $stdout, $stderr);
...

For custom termination life-cycle.

Binyamin
12 Jun, 2023, 16:48

And then the user should make sure is termination is very short, like other life-cycles logic.

Drake
12 Jun, 2023, 17:01

Theoretically, docker stop should send some signal, but I'm not sure which and why it's not propagating to the express server

Binyamin
13 Jun, 2023, 00:40

I've run a few tests, and no SIG* was received. It seems like that pm2 encourage the use of pm2-runtime inside Docker.

https://pm2.keymetrics.io/docs/usage/docker-pm2-nodejs/

nev-21
5 Jul, 2023, 13:45

Hi Binyamin,can you help me with a workaround?

rohit90314
5 Jul, 2023, 19:04

Docker does send signals but because of how the open runtimes are structured, the actual node function doesn’t receive that signal. Its one of the optimizations which we can make.

rohit90314
5 Jul, 2023, 19:11

Docker sends the signals to the pid 1 which here is npm script (the host start.sh, which creates a shell process with pid1), and then that signal is not relayed further hence our app doesn’t receive it

Drake
5 Jul, 2023, 19:45

so were you able to make any modifications to get the signal to propagate?

Binyamin
6 Jul, 2023, 02:22

That's actually a very good analyze of that matter, thanks

Binyamin
6 Jul, 2023, 03:04

It required some additional checks, and the idea was great. I've created a PR for that https://github.com/open-runtimes/open-runtimes/pull/171

rohit90314
6 Jul, 2023, 03:43

I didn’t get a chance to look into it in detail, but from high level it does look ok, I am only concerned a bit on moving the requite outside. Ideally this should not impact, but I don’t have the reasoning why it was put under in the first place. Also there should be a better way of doing this instead adding into every runtime, I have plans on looking into it but struggling with finding time😅

nev-21
19 Jul, 2023, 21:03
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more