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

transport: don't add connection to multiplexer if init fails #3931

Merged
merged 3 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func (t *Transport) init(isServer bool) error {
conn, err = wrapConn(t.Conn)
if err != nil {
t.initErr = err
getMultiplexer().RemoveConn(t.Conn)
return
}
}
Expand Down
24 changes: 24 additions & 0 deletions transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/tls"
"errors"
"net"
"syscall"
"time"

mocklogging "github.com/quic-go/quic-go/internal/mocks/logging"
Expand Down Expand Up @@ -307,4 +308,27 @@ var _ = Describe("Transport", func() {
pconn.EXPECT().Close()
Expect(tr.Close()).To(Succeed())
})

It("removes underlying PacketConn from multiplexer after (*Transport).init failed", func() {
marten-seemann marked this conversation as resolved.
Show resolved Hide resolved
packetChan := make(chan packetToRead)
pconn := newMockPacketConn(packetChan)
syscallconn := &mockSyscallConn{pconn}

tr := &Transport{
Conn: syscallconn,
}

err := tr.init(false)
Expect(err).To(HaveOccurred())
conns := getMultiplexer().(*connMultiplexer).conns
Expect(len(conns)).To(BeZero())
})
})

type mockSyscallConn struct {
net.PacketConn
}

func (c *mockSyscallConn) SyscallConn() (syscall.RawConn, error) {
return nil, errors.New("mocked")
}