Unlock fdbased.endpoint.mu before fdbased.endpoint.Wait().

This prevents the deadlock described in #11456.

Fixes #11456.

PiperOrigin-RevId: 725352718
This commit is contained in:
Ayush Ranjan
2025-02-10 14:45:27 -08:00
committed by gVisor bot
parent 0daeb1c40b
commit e161bec8dc
+4 -2
View File
@@ -422,17 +422,19 @@ func isSocketFD(fd int) (bool, error) {
// Attach implements stack.LinkEndpoint.Attach.
func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) {
e.mu.Lock()
defer e.mu.Unlock()
// nil means the NIC is being removed.
if dispatcher == nil && e.dispatcher != nil {
for _, dispatcher := range e.inboundDispatchers {
dispatcher.Stop()
}
e.Wait()
e.dispatcher = nil
// NOTE(gvisor.dev/issue/11456): Unlock e.mu before e.Wait().
e.mu.Unlock()
e.Wait()
return
}
defer e.mu.Unlock()
if dispatcher != nil && e.dispatcher == nil {
e.dispatcher = dispatcher
// Link endpoints are not savable. When transportation endpoints are