Thread-safety improvements in removeEndpoint and releaseConnection