Skip to content

Commit

Permalink
face: Add mutex for transport.sendFrame
Browse files Browse the repository at this point in the history
Fix: #56
  • Loading branch information
zjkmxy committed Nov 1, 2023
1 parent d9dc7b0 commit f36991f
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions face/ndnlp-link-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ type NDNLPLinkService struct {
bees []*WorkerBee
workQueue chan *ndn.PendingPacket
BufferReader enc.BufferReader

// This is to solve a concurrency problem introduced in commit a329946
// Low layer transports are not supposed to have sendFrame() called concurrently
// Search `go sendPacket(l, netPacket)` to find the line that causes this problems
// Ref: https://github.com/named-data/YaNFD/issues/56
sendFrameMutex sync.Mutex
}

type WorkerBee struct {
Expand Down Expand Up @@ -353,7 +359,11 @@ func sendPacket(l *NDNLPLinkService, netPacket *ndn.PendingPacket) {
break
}
// Use Join() for now
l.transport.sendFrame(frameWire.Join())
{
l.sendFrameMutex.Lock()
defer l.sendFrameMutex.Unlock()
l.transport.sendFrame(frameWire.Join())
}
}
}
func (l *NDNLPLinkService) runSend() {
Expand Down Expand Up @@ -404,7 +414,11 @@ func (l *NDNLPLinkService) runSend() {
break
}
// Use Join() for now
l.transport.sendFrame(frameWire.Join())
{
l.sendFrameMutex.Lock()
defer l.sendFrameMutex.Unlock()
l.transport.sendFrame(frameWire.Join())
}
}
}
case <-l.hasTransportQuit:
Expand Down

0 comments on commit f36991f

Please sign in to comment.