fix a possible crash at the end of a coroutine