Fix CloseOnHandshakeFailure

This commit is contained in:
世界 2024-12-04 17:14:58 +08:00
parent 809d8eca13
commit 957166799e
No known key found for this signature in database
GPG key ID: CD109927C34A63C4

View file

@ -33,7 +33,7 @@ func ReportHandshakeFailure(reporter any, err error) error {
return nil return nil
} }
func CloseOnHandshakeFailure(reporter any, onClose CloseHandlerFunc, err error) error { func CloseOnHandshakeFailure(reporter io.Closer, onClose CloseHandlerFunc, err error) error {
if err != nil { if err != nil {
if handshakeConn, isHandshakeConn := common.Cast[HandshakeFailure](reporter); isHandshakeConn { if handshakeConn, isHandshakeConn := common.Cast[HandshakeFailure](reporter); isHandshakeConn {
hErr := handshakeConn.HandshakeFailure(err) hErr := handshakeConn.HandshakeFailure(err)
@ -51,13 +51,11 @@ func CloseOnHandshakeFailure(reporter any, onClose CloseHandlerFunc, err error)
}](reporter); isTCPConn { }](reporter); isTCPConn {
tcpConn.SetLinger(0) tcpConn.SetLinger(0)
} }
if closer, isCloser := reporter.(io.Closer); isCloser { }
err = E.Append(err, closer.Close(), func(err error) error { err = E.Append(err, reporter.Close(), func(err error) error {
return E.Cause(err, "close") return E.Cause(err, "close")
}) })
} }
}
}
if onClose != nil { if onClose != nil {
onClose(err) onClose(err)
} }