Handle shutdown cases: sometimes destructor is not called