add safeguard against infinite loop with EINTR, even if that case is very unlikely