question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Process still running after exiting (SIGINT) from all spawned processes

See original GitHub issue

I’m trying to set a very simple configuration to concurrently run a localtunnel that points to a next localhost server.

The npm script is "concurrently -k \"next dev\" \"node tunnel/index.js\"" This scripts work well independently and they do so with concurently. The problem I’m facing is when I tried to exit from any of those, I got the visual feedback on stdout that clearly tells me that SIGINT was sent to both processes but the “master” process (concurrently) is still running and don’t return my prompt back. I have to sent an extra SIGINT to end it.

I have tried the same command without the “k” flag, tried using the --kill-others-on-fail flag and even the “s” flag with its 3 different settings. None of this configurations seems to solve the problem.

$ yarn run dev
yarn run v1.22.17
$ concurrently "next dev" "node tunnel/index.js"
[0] ready - started server on 0.0.0.0:3000, url: http://localhost:3000
[0] info  - Loaded env from /home/demian/Documents/CODE/SHOPIFY/apps/shopify-next-app/.env.local
[1] https://4490f7e2-6938-4ae2-9e4f-9106edc4ec4c.loca.lt
[0] event - compiled successfully in 2.3s (188 modules)
^C
demian:~/Documents/CODE/SHOPIFY/apps/shopify-next-app [master] 
$ [1] node tunnel/index.js exited with code SIGINT
[0] next dev exited with code SIGINT

The last blank line is the cursor hanging on the process which won’t return my prompt back if I don’t sent an extra SIGINT. To be clear both processes running independently don’t need an extra SIGINT to exit. This happens only when they are spawn by concurrently. And I’m not spawing any extra process within the localtunnel. The code for the tunnel is fairly simple.

const localtunnel = require("localtunnel");
const { exec } = require("child_process");
const { randomUUID } = require("crypto");
const fs = require("fs");
const { join } = require("path");

let uuid = "";
const uuidPath = join(__dirname, "uuid");

// Making your tunnel URL unique and persistant across executions
if (fs.existsSync(uuidPath)) {
  uuid = fs.readFileSync(uuidPath, "utf8");
} else {
  uuid = randomUUID();
  fs.writeFileSync(uuidPath, uuid);
}

// https://github.com/localtunnel/localtunnel#api
const init = async () => {
  const tunnel = await localtunnel({ port: 3000, subdomain: uuid });
  console.log(tunnel.url);
  tunnel.on("close", () => {});
};

init();

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
compulimcommented, Dec 25, 2021

On my side, the problem is from lerna@4, which I use to run concurrently.

https://github.com/lerna/lerna/issues/2284

I tested few scenarios on Windows (outside of lerna), such as nesting concurrently and it looks good to me so far.

1reaction
denik1981commented, Dec 24, 2021

@tjni Actually that last ^C that is logged in the console, refers to the extra CTRL+C I was needing here to end the process. Only after that is when the prompt returns back to me. For the second run, I killed the 2 concurrent process so to show here that the prompt isn’t coming back to me when there is nothing left to kill.

@gustavohenke Sorry, I don’t have a record of the repo as I move on using a different approach but I was using:

  • node@16.13.0
  • LinuxOS 5.11.0-43-generic 47~20.04.2-Ubuntu
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does this script keep running after receiving SIGINT?
When a process exits with SIGINT, its exit status can be read by wait(2) . By using WIFSIGNALED and WTERMSIG , bash can...
Read more >
NodeJS child processes are terminated on SIGINT
When running processes are killed by SIGINT, new processes that were queued are started just fine and finishes successfully. I have problem only ......
Read more >
Orphaned child processes keep running when exiting `lerna ...
The process continues to run until it completes, but lerna exits immediately. It seems like these signals should be sent to child processes...
Read more >
Proper handling of SIGINT/SIGQUIT
If the shell executing a script received SIGINT while a foreground process was running, it will exit after that child's exit.
Read more >
Erlang -- Processes
If the receiver is set in an exiting state, no more Erlang code will be executed and the process is scheduled for termination....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found