Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle ENOBUFS when writing to VM socket #370

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we should use conn.SetWriteDeadline when there's ENOBUFS to be sure we're not getting into an infinite loop.
But looks good to me as is, we can refine it further if there are issues.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is an option I guess, my basic understanding is that could only happen if the reader side (VM process) no longer reads anything from the socket but still keeps the socket open.
Sounds rather unlikely to me but yes if this turn out to cause problems we can add a deadline later

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
Loading