JP Camara @jpcamara.com · Nov 2

1) @mike.contribsys.com you clever devil, that Signal.trap approach is ingenious! In my post on thread interrupts, I mentioned that you cannot use rails.logger inside of a signal.trap: bit.ly/43c23Ym. Similarly, you cannot use the Sidekiq logger in trap, which is inconvenient. 3/11 🧵

2 likes 2 replies

?

Replies

JP Camara · Nov 2

The full reasons for that are explained in docs.ruby-lang.org/en/3.4/signa..., and have to do with a concept called "reentrancy". But mike bypasses all of that by using using IO.pipe. The io writer is safe to write to in the trap, so that's all it does, it writes the signal. 4/11 🧵

Jean Boussier · Nov 2

That's called the "Self Pipe Trick" It's pretty much textbook how to handle signals in an application with a main IO loop.