SplitHTTP: Fix connection leaks and crashes (#3710)

This commit is contained in:
mmmray
2024-08-22 17:07:57 +02:00
committed by GitHub
parent 2be03c56cb
commit 83eef6bc1f
7 changed files with 109 additions and 65 deletions

View File

@@ -248,6 +248,8 @@ func Test_listenSHAndDial_QUIC(t *testing.T) {
NextProtocol: []string{"h3"},
},
}
serverClosed := false
listen, err := ListenSH(context.Background(), net.LocalHostIP, listenPort, streamSettings, func(conn stat.Connection) {
go func() {
defer conn.Close()
@@ -258,10 +260,12 @@ func Test_listenSHAndDial_QUIC(t *testing.T) {
for {
b.Clear()
if _, err := b.ReadFrom(conn); err != nil {
return
break
}
common.Must2(conn.Write(b.Bytes()))
}
serverClosed = true
}()
})
common.Must(err)
@@ -271,7 +275,6 @@ func Test_listenSHAndDial_QUIC(t *testing.T) {
conn, err := Dial(context.Background(), net.UDPDestination(net.DomainAddress("localhost"), listenPort), streamSettings)
common.Must(err)
defer conn.Close()
const N = 1024
b1 := make([]byte, N)
@@ -294,6 +297,12 @@ func Test_listenSHAndDial_QUIC(t *testing.T) {
t.Error(r)
}
conn.Close()
time.Sleep(100 * time.Millisecond)
if !serverClosed {
t.Error("server did not get closed")
}
end := time.Now()
if !end.Before(start.Add(time.Second * 5)) {
t.Error("end: ", end, " start: ", start)