[PATCH] Add timeout to _poll_loop function to avoid infinite looping