Hacker News new | ask | show | jobs
by jeff-davis 740 days ago
Longjmp is used by Postgres for transaction aborts. With C, there's not really a better option available.
1 comments

That's not from within signal handlers, though. (i.e. it relates to this specific longjmp discussion but not the root post re. exceptions on other threads.)
It unfortunately is used from within signal handlers, albeit only in specific cases (SIGFPE). There used to several more, but we luckily largely cleaned that up over the last few years.
Meh. Well. Good to hear on the cleanup. Didn't know it used to be different :/

Re. SIGFPE, to be fair, it feels a bit like the "asynchronous vs. synchronous abort¹" thing on CPUs; synchronous aborts are reasonably doable while on asynchronous aborts you're pretty much left with torching things down far and wide.

(SIGFPE should hopefully be synchronous; it's in fact closely connected to sync/async CPU aborts...)

[¹ frequently also called exceptions, depending on the CPU architecture, but this post already uses "exception" for the language level concept]

> Meh. Well. Good to hear on the cleanup. Didn't know it used to be different :/

If you want to be scared: Until not too long ago postgres' supervisor process would start some types of subprocesses from within a signal handler... Not entirely surprisingly, that found bugs in various debugging tools (IIRC at least valgrind, rr, one of the sanitizer libs).

> Re. SIGFPE, to be fair, it feels a bit like the "asynchronous vs. synchronous abort¹" thing on CPUs; synchronous aborts are reasonably doable while on asynchronous aborts you're pretty much left with torching things down far and wide.

Agreed, I think it's quite reasonable to use signals + longjmp() for the FP error case. In fact, I think we should do so more widely - we loose a fair bit of performance due to all kinds of floating point error checking that we could set up to instead signal.