Skip to content

Commit

Permalink
Protect WritePackets with mutex
Browse files Browse the repository at this point in the history
Introducing mutex without implementing buffered channel may
halt reads until replywithReset is sent. Buffering smooths
the reads till the chan capacity is exceeded

Signed-off-by: Vasyl Gello <[email protected]>
  • Loading branch information
basilgello committed Jul 17, 2024
1 parent b8879a4 commit b3b5337
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/netstack/yggdrasil.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package netstack
import (
"log"
"net"
"sync"

"github.com/yggdrasil-network/yggdrasil-go/src/core"
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
Expand All @@ -19,6 +20,7 @@ type YggdrasilNIC struct {
ipv6rwc *ipv6rwc.ReadWriteCloser
dispatcher stack.NetworkDispatcher
readBufChan chan *stack.PacketBuffer
writeLock sync.Mutex
writeBuf []byte
}

Expand Down Expand Up @@ -102,6 +104,8 @@ func (*YggdrasilNIC) Wait() {}
func (e *YggdrasilNIC) WritePackets(
list stack.PacketBufferList,
) (int, tcpip.Error) {
e.writeLock.Lock()
defer e.writeLock.Unlock()
var i int = 0
for i, pkt := range list.AsSlice() {
vv := pkt.ToView()
Expand Down

0 comments on commit b3b5337

Please sign in to comment.