fix potential endless loop in signal handler