From 3f44cd556b7fda0c56b4665959c52afc5e425d88 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Tue, 10 May 2022 22:14:27 -0700 Subject: [PATCH] sentry/socket: don't release a connected enpoint under the endpoint mutex It isn't required and can have side effects. For example, the current endpoint can be in an SCM message that is queued to the connected endpoint. PiperOrigin-RevId: 447906621 --- pkg/sentry/socket/unix/transport/connectionless.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/sentry/socket/unix/transport/connectionless.go b/pkg/sentry/socket/unix/transport/connectionless.go index 9d5d63fbe..80929c0a9 100644 --- a/pkg/sentry/socket/unix/transport/connectionless.go +++ b/pkg/sentry/socket/unix/transport/connectionless.go @@ -59,10 +59,8 @@ func (e *connectionlessEndpoint) isBound() bool { // with it. func (e *connectionlessEndpoint) Close(ctx context.Context) { e.Lock() - if e.connected != nil { - e.connected.Release(ctx) - e.connected = nil - } + connected := e.connected + e.connected = nil if e.isBound() { e.path = "" @@ -73,6 +71,9 @@ func (e *connectionlessEndpoint) Close(ctx context.Context) { e.receiver = nil e.Unlock() + if connected != nil { + connected.Release(ctx) + } r.CloseNotify() r.Release(ctx) }