Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git bash terminal on windows doesn't send any signal on close ( at least it seems like it ) #1258

Open
C0D3O opened this issue Mar 19, 2024 · 5 comments
Labels

Comments

@C0D3O
Copy link

C0D3O commented Mar 19, 2024

Or does it? Thank you

@mintty
Copy link
Owner

mintty commented Mar 19, 2024

It does.
What are the symptoms that make you ask this?

@C0D3O
Copy link
Author

C0D3O commented Mar 19, 2024

It does. What are the symptoms that make you ask this?

I have such code, node js express server

import express from 'express';
import cors from 'cors';
import { WebSocketServer } from 'ws';

const wss = new WebSocketServer({
	port: 8080,
});

const app = express();
app.options('*', cors());
app.use(cors());
app.use(express.json());

const server = app.listen(8000, () => {
	console.log(`Server is running on port 8000`);
});

process.on('SIGQUIT', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGQUIT');
	process.exit();
});
process.on('SIGTERM', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGTERM');
	process.exit();
});
process.on('SIGINT', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGINT');
	process.exit();
});
process.on('SIGBREAK', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGBREAK');
	process.exit();
});
process.on('SIGHUP', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGHUP');
	process.exit();
});
process.on('SIGUSR1', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGUSR1');
	process.exit();
});
process.on('SIGUSR2', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGUSR2');
	process.exit();
});
process.on('SIGTTOU', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGTTOU');
	process.exit();
});
process.on('SIGTTIN', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGTTIN');
	process.exit();
});
process.on('SIGTSTP', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGTSTP');
	process.exit();
});
process.on('SIGCHLD', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGCHLD');
	process.exit();
});
process.on('SIGTTOU', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGTTOU');
	process.exit();
});
process.on('SIGTRAP', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGTRAP');
	process.exit();
});
process.on('SIGABRT', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGABRT');
	process.exit();
});
process.on('SIGFPE', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGFPE');
	process.exit();
});
process.on('SIGBUS', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGBUS');
	process.exit();
});
process.on('SIGSEGV', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGSEGV');
	process.exit();
});
process.on('SIGPIPE', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGPIPE');
	process.exit();
});
process.on('SIGSYS', () => {
	wss.close();
	server.close();
	writeFileSync('./1.txt', 'SIGSYS');
	process.exit();
});

I've looked through this repository to gather all the signals, and it seems none of them are being sent on a git bash terminal close

So I open windows terminal and the git bash.. terminal there.. run my server, then I close the terminal by clicking on the 'x' button at the top right of the window.. then I reopen a terminal, run the server again, and it throws port blabla is already in use, so this means that the prev server wasn't close on the terminal window close, and I'd like it to do so... so that's why I'm asking this. Thank you:)

when I press ctrl+c then SIGINT is sent, ok, but I want the process to close gracefully just on a terminal window close without pressing ctrl+c

@mintty
Copy link
Owner

mintty commented Mar 21, 2024

When asked to quit, mintty checks whether to prompt for confirmation. If quitting is not cancelled, it sends a SIGHUP to its child process group, unless the Shift key is also pressed, in which case it sends SIGKILL.
The issue in your case may be that you run a native Windows program on cygwin (as far as I know, there is no cygwin native node release), and signal handling does not have good interworking between cygwin and a Windows subprocess.

@C0D3O
Copy link
Author

C0D3O commented Mar 21, 2024

When asked to quit, mintty checks whether to prompt for confirmation. If quitting is not cancelled, it sends a SIGHUP to its child process group, unless the Shift key is also pressed, in which case it sends SIGKILL. The issue in your case may be that you run a native Windows program on cygwin (as far as I know, there is no cygwin native node release), and signal handling does not have good interworking between cygwin and a Windows subprocess.

I see... soo the only option is to use some windows terminal? or maybe there is still a way to make it work with git bash? Thank you

@mintty
Copy link
Owner

mintty commented May 14, 2024

Getting back to this...
I explained that mintty does send a signal and that the signal may not reach your application if it is a native Windows one.
Signal interworking between cygwin and Windows might be improvable, but that would not be an issue of the terminal but of either the cygwin kernel or its conpty support layer. Please address this issue to the cygwin mailing list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants