From 57af3d28b3adf16caedbde34e7d046ae37fc1930 Mon Sep 17 00:00:00 2001 From: Shahriyar Jalayeri Date: Wed, 27 Nov 2024 22:59:39 +0200 Subject: [PATCH] vsock: set read/write timeout on the accepted connection 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 --- pkg/pillar/cmd/vcomlink/vsocksrv.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/pillar/cmd/vcomlink/vsocksrv.go b/pkg/pillar/cmd/vcomlink/vsocksrv.go index 0884308b2b..c82739b288 100644 --- a/pkg/pillar/cmd/vcomlink/vsocksrv.go +++ b/pkg/pillar/cmd/vcomlink/vsocksrv.go @@ -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 { @@ -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) } }