IO: tie lifetime of handle field to container (#43218)
Rather than freeing this memory as soon as possible, ensure that the
lifetime of the handle is always >= the container object. This lets us
examine some (limited) aspects of the handle without holding a lock.
And we also examine and fix numerous other thread-safety and
synchronization bugs too.