mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
fix: ensure StreamWebsocketConn call N.NewDeadlineConn
This commit is contained in:
parent
b51b258f36
commit
0e2f5e4436
|
@ -79,3 +79,7 @@ func (c *BufferedConn) ReaderReplaceable() bool {
|
|||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *BufferedConn) WriterReplaceable() bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -334,7 +334,10 @@ func streamWebsocketWithEarlyDataConn(conn net.Conn, c *WebsocketConfig) (net.Co
|
|||
underlay: conn,
|
||||
config: c,
|
||||
}
|
||||
return conn, nil
|
||||
// websocketWithEarlyDataConn can't correct handle Deadline
|
||||
// it will not apply the already set Deadline after Dial()
|
||||
// so call N.NewDeadlineConn to add a safe wrapper
|
||||
return N.NewDeadlineConn(conn), nil
|
||||
}
|
||||
|
||||
func streamWebsocketConn(conn net.Conn, c *WebsocketConfig, earlyData *bytes.Buffer) (net.Conn, error) {
|
||||
|
@ -402,11 +405,16 @@ func streamWebsocketConn(conn net.Conn, c *WebsocketConfig, earlyData *bytes.Buf
|
|||
return nil, fmt.Errorf("dial %s error: %s", uri.Host, reason)
|
||||
}
|
||||
|
||||
return &websocketConn{
|
||||
conn = &websocketConn{
|
||||
conn: wsConn,
|
||||
rawWriter: N.NewExtendedWriter(wsConn.UnderlyingConn()),
|
||||
remoteAddr: conn.RemoteAddr(),
|
||||
}, nil
|
||||
}
|
||||
// websocketConn can't correct handle ReadDeadline
|
||||
// gorilla/websocket will cache the os.ErrDeadlineExceeded from conn.Read()
|
||||
// it will cause read fail and event panic in *websocket.Conn.NextReader()
|
||||
// so call N.NewDeadlineConn to add a safe wrapper
|
||||
return N.NewDeadlineConn(conn), nil
|
||||
}
|
||||
|
||||
func StreamWebsocketConn(conn net.Conn, c *WebsocketConfig) (net.Conn, error) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user