Skip to content

Commit

Permalink
vsock: set read/write timeout on the accepted connection
Browse files Browse the repository at this point in the history
Set the read/write timeout on the accepted connection instead of the
listner, otherwise accept will compain with EAGAIN every TIMEOUT seconds.

Signed-off-by: Shahriyar Jalayeri <[email protected]>
  • Loading branch information
shjala authored and OhmSpectator committed Nov 29, 2024
1 parent 2c5c47d commit 6d42661
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions pkg/pillar/cmd/vcomlink/vsocksrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,6 @@ func startVcomServer(listener SocketListener) {
}
defer unix.Close(fd)

// Set read timeout and write timeout
err = unix.SetsockoptTimeval(fd, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &unix.Timeval{Sec: readTimeout})
if err != nil {
log.Errorf("Error setting read timeout: %v", err)
return
}
err = unix.SetsockoptTimeval(fd, unix.SOL_SOCKET, unix.SO_SNDTIMEO, &unix.Timeval{Sec: writeTimeout})
if err != nil {
log.Errorf("Error setting write timeout: %v", err)
return
}

for {
conn, _, err := unix.Accept(fd)
if err != nil {
Expand All @@ -69,6 +57,18 @@ func startVcomServer(listener SocketListener) {
continue
}

// Set read timeout and write timeout
err = unix.SetsockoptTimeval(conn, unix.SOL_SOCKET, unix.SO_RCVTIMEO, &unix.Timeval{Sec: readTimeout})
if err != nil {
log.Errorf("error setting read timeout: %v", err)
return
}
err = unix.SetsockoptTimeval(conn, unix.SOL_SOCKET, unix.SO_SNDTIMEO, &unix.Timeval{Sec: writeTimeout})
if err != nil {
log.Errorf("error setting write timeout: %v", err)
return
}

go handleConnection(conn)
}
}
Expand Down

0 comments on commit 6d42661

Please sign in to comment.