mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-08-23 10:06:48 +08:00
SplitHTTP: Fix connection leaks and crashes (#3710)
This commit is contained in:
@@ -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)
|
||||
|
Reference in New Issue
Block a user