As @rwatson mentioned in D15706, a "socket destructor" should actuall run when the socket is destroyed.
Update the socket destructor functionality to run when a socket is destroyed (rather than when it is closed). The original submitter has confirmed that this change satisfies the intended use case.