From 7782952880c39533ac65adbd2fb92a662214c581 Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Wed, 17 Jul 2024 13:27:20 +0200 Subject: [PATCH 1/2] handle ENOBUFS when writing to VM socket When a high throughput is happeing we send a lot of data into the VM socket, the VM has to read it in order to empty the buffer. This is inherently race so it is possible to get ENOBUFS here. In this case just keep trying writing until it works. Fixes #367 Signed-off-by: Paul Holzinger --- pkg/tap/switch.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/tap/switch.go b/pkg/tap/switch.go index 10fe59e3b..5f1d16f35 100644 --- a/pkg/tap/switch.go +++ b/pkg/tap/switch.go @@ -7,6 +7,7 @@ import ( "net" "sync" "sync/atomic" + "syscall" "github.com/containers/gvisor-tap-vsock/pkg/types" "github.com/google/gopacket" @@ -167,18 +168,21 @@ func (e *Switch) txBuf(id int, conn protocolConn, buf []byte) error { if conn.protocolImpl.Stream() { size := conn.protocolImpl.(streamProtocol).Buf() conn.protocolImpl.(streamProtocol).Write(size, len(buf)) - - if _, err := conn.Write(append(size, buf...)); err != nil { - e.disconnect(id, conn) - return err - } - } else { + buf = append(size, buf...) + } + for { if _, err := conn.Write(buf); err != nil { + if errors.Is(err, syscall.ENOBUFS) { + // socket buffer can be full keep retrying sending the same data + // again until it works or we get a different error + // https://github.com/containers/gvisor-tap-vsock/issues/367 + continue + } e.disconnect(id, conn) return err } + return nil } - return nil } func (e *Switch) disconnect(id int, conn net.Conn) { From 0e970bf83b2b138946eabf78a83dbbf7badc6bdf Mon Sep 17 00:00:00 2001 From: Paul Holzinger Date: Tue, 23 Jul 2024 10:28:41 +0200 Subject: [PATCH 2/2] test: fix broken dns TXT lookup test It sems the TXT entry for wikipedia.org changed which is causing the test to fail. Fix it by only checking for a partial match and use a domain that is under our control (crc.dev). Signed-off-by: Paul Holzinger --- test/basic_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/basic_test.go b/test/basic_test.go index e51864f00..a3db89e7e 100644 --- a/test/basic_test.go +++ b/test/basic_test.go @@ -74,10 +74,10 @@ var _ = ginkgo.Describe("dns", func() { gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) gomega.Expect(string(out)).To(gomega.ContainSubstring(`_ldap._tcp.google.com service = 5 0 389 ldap.google.com.`)) }) - ginkgo.It("should resolve TXT for wikipedia.org", func() { - out, err := sshExec("nslookup -query=txt wikipedia.org") + ginkgo.It("should resolve TXT for crc.dev", func() { + out, err := sshExec("nslookup -query=txt crc.dev") gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - gomega.Expect(string(out)).To(gomega.ContainSubstring(`"v=spf1 -all"`)) + gomega.Expect(string(out)).To(gomega.ContainSubstring(`text = "v=spf1`)) }) ginkgo.It("should resolve gateway.containers.internal", func() {