548471717a
When a QUIC session's MaxIdleTimeout expires, the underlying *quic.Conn dies but the dead quicSession stays in the sessions map. The next Dial() finds it and calls session.GetConn() which calls OpenStreamSync(context.Background()) against the dead connection — blocking indefinitely. Add IsClosed() to both quicSession types (using the session context's Done() channel) and add the liveness guard in both Dial() methods, matching the existing pattern in KCP and MASQUE dialers. Fixes go-gost/gost#225
52 lines
880 B
Go
52 lines
880 B
Go
package quic
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
|
|
"github.com/quic-go/quic-go"
|
|
)
|
|
|
|
type quicSession struct {
|
|
session *quic.Conn
|
|
}
|
|
|
|
func (session *quicSession) GetConn() (*quicConn, error) {
|
|
stream, err := session.session.OpenStreamSync(context.Background())
|
|
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
|
|
}
|