Fix ruby21 mutex lock within trap

Fixes https://bugs.ruby-lang.org/issues/7917. Inspiration from https://github.com/websocket-rails/websocket-rails/commit/064dc912ecde718ab2d8ec79382e89ea361de7af