From 0927d6a10c4cfe46ea0c805a1c53170c52c93dbf Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Wed, 29 Sep 2021 13:08:41 -0700 Subject: [PATCH] socket/unix: close sockets from acceptedChan after releasing the endpoint lock I am working on the lock validator and this change helps to avoid false-positive reports of nested dependencies. Signed-off-by: Andrei Vagin --- pkg/sentry/socket/unix/transport/connectioned.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/sentry/socket/unix/transport/connectioned.go b/pkg/sentry/socket/unix/transport/connectioned.go index 673c80a60..14a17ef2e 100644 --- a/pkg/sentry/socket/unix/transport/connectioned.go +++ b/pkg/sentry/socket/unix/transport/connectioned.go @@ -209,6 +209,7 @@ func (e *connectionedEndpoint) Listening() bool { // That is, close may be used to "unbind" or "disconnect" the socket in error // paths. func (e *connectionedEndpoint) Close(ctx context.Context) { + var acceptedChan chan *connectionedEndpoint e.Lock() var c ConnectedEndpoint var r Receiver @@ -229,13 +230,16 @@ func (e *connectionedEndpoint) Close(ctx context.Context) { e.path = "" case e.Listening(): close(e.acceptedChan) - for n := range e.acceptedChan { - n.Close(ctx) - } + acceptedChan = e.acceptedChan e.acceptedChan = nil e.path = "" } e.Unlock() + if acceptedChan != nil { + for n := range acceptedChan { + n.Close(ctx) + } + } if c != nil { c.CloseNotify() c.Release(ctx)