Swoole – solve “WARNING Worker_reactor_try_to_exit() (ERRNO 9012): worker exit timeout, forced termination”

I’ve recently ran into this error message with mezzio/swoole – which would popup for every hot reload on code change.

Ive tried couple of different things (completely on the hunch) like:

  • disabling ticks (this didn’t help)
  • disabling side swoole processes (this didn’t help)
  • raising max_wait_time to 60 seconds (this didn’t help)
  • checking mysql/redis connection pools and closing on worker exit (this didn’t help)

But nothing seemed to work.

Solved this thanks to a friendly advice from openswoole slack channel:

 public function onWorkerExit(int $worker_id): void
 {
        //Prevent worker exit timeout issues (similar to die/exit)
        //@see: https://openswoole.com/docs/modules/swoole-event-exit
        \Swoole\Timer::clearAll();
        \Swoole\Event::Exit();
 }

Basically adding these 2 instructions in onWorkerExit event solved the timeout issues for me. ofc would be nice to understand why – but this solved the immediate issues for us.

Hope this helps some other stragglers!

Leave a Comment