Fix in_tail shutdown race condition problem

See the comment in diff.