9fab332772
The ICMP dialer required explicit keepalive:true to send QUIC PING frames, while the regular QUIC dialer enabled keepalive by default (10s period). Without PING frames, quic-go's 30s idle timeout silently killed connections, causing HTTP+ICMP tunnels to hang after periods of inactivity. Fixes go-gost/gost#352 Also in this commit: - Release session mutex before calling GetConn() in both ICMP and QUIC dialers, so a dead session doesn't block all Dial() calls while OpenStreamSync blocks - Add 30s timeout context to OpenStreamSync to prevent indefinite blocking if the QUIC session dies between liveness check and stream open - Guard session cache deletion with pointer identity check to avoid evicting a newly created session during a race
55 lines
961 B
Go
55 lines
961 B
Go
package quic
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"time"
|
|
|
|
"github.com/quic-go/quic-go"
|
|
)
|
|
|
|
type quicSession struct {
|
|
session *quic.Conn
|
|
}
|
|
|
|
func (session *quicSession) GetConn() (*quicConn, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
defer cancel()
|
|
stream, err := session.session.OpenStreamSync(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &quicConn{
|
|
Stream: stream,
|
|
laddr: session.session.LocalAddr(),
|
|
raddr: session.session.RemoteAddr(),
|
|
}, nil
|
|
}
|
|
|
|
func (session *quicSession) IsClosed() bool {
|
|
select {
|
|
case <-session.session.Context().Done():
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
func (session *quicSession) Close() error {
|
|
return session.session.CloseWithError(quic.ApplicationErrorCode(0), "closed")
|
|
}
|
|
|
|
type quicConn struct {
|
|
*quic.Stream
|
|
laddr net.Addr
|
|
raddr net.Addr
|
|
}
|
|
|
|
func (c *quicConn) LocalAddr() net.Addr {
|
|
return c.laddr
|
|
}
|
|
|
|
func (c *quicConn) RemoteAddr() net.Addr {
|
|
return c.raddr
|
|
}
|