@@ -415,10 +415,12 @@ func (s *Socket) HandleInterfaceChangeEvent(ctx context.Context, idx int32, i in
415415 panic (fmt .Sprintf ("Non-ROUTE netlink socket (protocol %d) cannot handle interface events" , s .Protocol ()))
416416 }
417417
418- s .mu .Lock ()
419- portID := s .portID
420- s .mu .Unlock ()
421- ms := nlmsg .NewMessageSet (portID , 0 )
418+ // s.portID is protected by s.mu. But we cannot take s.mu because it already may
419+ // be held across sendMsg() -> Protocol.Receive() -> ProcessMessages() -> ...
420+ // -> protocol.ProcessMessage() -> Socket.SendResponse(). The racy access to s.portID
421+ // happens to be okay because once bound, a netlink socket's port ID is immutable.
422+ // TODO(b/435491173): Stop holding s.mu across the chain above.
423+ ms := nlmsg .NewMessageSet (s .portID , 0 )
422424 routeProtocol .AddNewLinkMessage (ms , idx , i )
423425 // TODO(b/456238795): Implement netlink ENOBUFS.
424426 s .SendResponse (ctx , ms )
@@ -431,10 +433,12 @@ func (s *Socket) HandleInterfaceDeleteEvent(ctx context.Context, idx int32, i in
431433 panic (fmt .Sprintf ("Non-ROUTE netlink socket (protocol %d) cannot handle interface events" , s .Protocol ()))
432434 }
433435
434- s .mu .Lock ()
435- portID := s .portID
436- s .mu .Unlock ()
437- ms := nlmsg .NewMessageSet (portID , 0 )
436+ // s.portID is protected by s.mu. But we cannot take s.mu because it already may
437+ // be held across sendMsg() -> Protocol.Receive() -> ProcessMessages() -> ...
438+ // -> protocol.ProcessMessage() -> Socket.SendResponse(). The racy access to s.portID
439+ // happens to be okay because once bound, a netlink socket's port ID is immutable.
440+ // TODO(b/435491173): Stop holding s.mu across the chain above.
441+ ms := nlmsg .NewMessageSet (s .portID , 0 )
438442 routeProtocol .AddDelLinkMessage (ms , idx , i )
439443 // TODO(b/456238795): Implement netlink ENOBUFS.
440444 s .SendResponse (ctx , ms )
0 commit comments