Skip to content

Commit

Permalink
Merge pull request #370 from Luap99/ENOBUFS
Browse files Browse the repository at this point in the history
handle ENOBUFS when writing to VM socket
  • Loading branch information
openshift-merge-bot[bot] authored Jul 23, 2024
2 parents 6dbbe08 + 0e970bf commit a3a9c41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
18 changes: 11 additions & 7 deletions pkg/tap/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net"
"sync"
"sync/atomic"
"syscall"

"github.com/containers/gvisor-tap-vsock/pkg/types"
"github.com/google/gopacket"
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a3a9c41

Please sign in to comment.