Process still running after exiting (SIGINT) from all spawned processes
See original GitHub issueI’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:
- Created 2 years ago
- Comments:6 (1 by maintainers)
On my side, the problem is from
lerna@4
, which I use to runconcurrently
.https://github.com/lerna/lerna/issues/2284
I tested few scenarios on Windows (outside of
lerna
), such as nestingconcurrently
and it looks good to me so far.@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: