Prevent deadlock when releasing socket