| 20 | static std::atomic_flag is_terminating = ATOMIC_FLAG_INIT; |
| 21 | |
| 22 | static inline void signal_handler(int signal) { |
| 23 | if (is_terminating.test_and_set()) { |
| 24 | // in case it hangs, we can force terminate the server by hitting Ctrl+C twice |
| 25 | // this is for better developer experience, we can remove when the server is stable enough |
| 26 | fprintf(stderr, "Received second interrupt, terminating immediately.\n"); |
| 27 | exit(1); |
| 28 | } |
| 29 | |
| 30 | shutdown_handler(signal); |
| 31 | } |
| 32 | |
| 33 | // wrapper function that handles exceptions and logs errors |
| 34 | // this is to make sure handler_t never throws exceptions; instead, it returns an error response |