Fix timed-out wait handling

Found by testing.