Live data from Hacker News

Beyond Ctrl-C: The dark corners of Unix signal handling

sunshowers.io

51–60 of 76 posts

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#51
post #50

Earlier quoted context omitted.

Disagree. Annoyingly there is a reasonable case for 200 but with an error, if http is your transport but not your application, then 200 says "yes, the message was transfered and understood correctly, here is your response" which may be an error response from the application

Which is why "you resized the terminal window, clearly you meant to shut down this web server" is even crazier , yes

Indeed. That is particularly good at violating the principle of least astonishment

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#52

Earlier quoted context omitted.

dd prints out status when sent SIGUSR1, but yeah that would be cool if other utilities did that as well off SIGINFO.

And does ^T map to SIGUSR1? That's the other thing which makes it so useful in BSD.

You wouldn’t want it to, because the default behavior for SIGUSR1 is to terminate.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#53
post #34

Earlier quoted context omitted.

For example: Apache (httpd) replaces the 4xx and 5xx response body with its own content instead of whatever you'd returned from an external handler like wsgi. You have to use a 2xx (except for 204) to get a relevant error message back out.

> For example: Apache (httpd) replaces the 4xx and 5xx response body with its own content instead of whatever you'd returned from an external handler like wsgi. This is the default behavior. Apache httpd can be configured to produce different responses by way of ErrorDocument[0]. From the documentation: Customized error responses can be defined for any HTTP status code designated as an error condition - that is, any…

Even with custom error documents configured in the web server, you still lose the application-specific (and probably request- and error-specific) message generated by the application itself.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#54

Earlier quoted context omitted.

> For example: Apache (httpd) replaces the 4xx and 5xx response body with its own content instead of whatever you'd returned from an external handler like wsgi. This is the default behavior. Apache httpd can be configured to produce different responses by way of ErrorDocument[0]. From the documentation: Customized error responses can be defined for any HTTP status code designated as an error condition - that is, any…

Even with custom error documents configured in the web server, you still lose the application-specific (and probably request- and error-specific) message generated by the application itself.

Yeah, this is how we ran across it - whoever originally wrote a particular feature was trying to do the right thing by using an HTTP error code, but with a message that would be presented to the user about why that operation failed. A generic response wouldn't work, there were multiple possible reasons all fixable by the user, and tying a whole error code to one specific feature would've probably been a bad idea anyway.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#55
post #20

Earlier quoted context omitted.

Why? That's what SIGTERM is for.

They use SIGWINCH for gracefully shutting down workers but not the main process [0]. SIGQUIT is used for a graceful shutdown and SIGTERM for a sort of graceful shutdown (with timeouts). SIGWINCH is apparently used for an online upgrade [1]. Because it only shuts the workers down you can quickly transition back to the old binary and old configuration if there's a problem, even after upgrading the binary or config stor…

[deleted]

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#56
post #11
post #2

My favorite signal surprise was running nginx and/or httpd in the foreground and wondering why on earth it quit whenver i resized the window. Turns out, they use SIGWINCH (which is sent on WINdow CHange) for graceful shutdown. It's a silly, silly problem.

> Turns out, they use SIGWINCH (which is sent on WINdow CHange) for graceful shutdown. That’s … that’s even worse than people who send errors with an HTTP 200 response code.

That's ... not what most people are doing. People send _application_ errors on HTTP 200 response codes, because HTTP response codes are for HTTP and not applications. Most "REST" libraries and webdev get this wrong, building ever more fragile web services.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#57
post #4

> Another common extension is to use what is sometimes called a double Ctrl-C pattern. The first time the user hits Ctrl-C, you attempt to shut down the database cleanly, but the second time you encounter it, you give up and exit immediately. This is a terrible behavior, because users tend to hit Ctrl-C multiple times without intending anything different than on a single hit (not to mention bouncing key mechanics and…

They can print a message that states that it is attempting to quit cleanly but can be forced to quit by pressing Ctrl+C another time(s). Unison does this.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#58

Earlier quoted context omitted.

And does ^T map to SIGUSR1? That's the other thing which makes it so useful in BSD.

You wouldn’t want it to, because the default behavior for SIGUSR1 is to terminate.

Exactly. Whereas on BSD hitting ^T is (a) very likely to print useful information, and (b) if it doesn't do that, won't do anything at all.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#59
post #10

Earlier quoted context omitted.

> Unclean exits should be reserved for SIGQUIT (Ctrl-\) and SIGKILL (by definition). I don't know how it works on your keyboard but on french layout, Ctrl-\ is a two-hands, three-fingers, very unpleasant on the wrist, keyboard shortcut. Not a chance I'd use that for such a common operation.

While on UK keyboards it's the opposite "problem" - the left Ctrl key and the \ key are right next to each other (making it potentially a one-finger operation), which is the opposite of how a US keyboard is laid out (where Ctrl-\ was presumably intended to need to be a two-handed, two-finger operation).

two handed operations shouldn't exist.

Re: Beyond Ctrl-C: The dark corners of Unix signal handling

#60
post #11

Earlier quoted context omitted.

> Turns out, they use SIGWINCH (which is sent on WINdow CHange) for graceful shutdown. That’s … that’s even worse than people who send errors with an HTTP 200 response code.

That's ... not what most people are doing. People send _application_ errors on HTTP 200 response codes, because HTTP response codes are for HTTP and not applications. Most "REST" libraries and webdev get this wrong, building ever more fragile web services.

Applications using status codes is useful because it can tell browsers and load balancers to not cache the page in a uniform way.
Post reply on HN