Fix: thread safety of the libevent event loop (#17031)