Remove direct read from TLS underlying conn (#3138)

This commit is contained in:
Francesco Renzi 2024-10-07 10:23:11 +01:00 committed by GitHub
parent d9eeed131a
commit e7868623ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 0 additions and 23 deletions

View File

@ -3,7 +3,6 @@
package pool package pool
import ( import (
"crypto/tls"
"errors" "errors"
"io" "io"
"net" "net"
@ -17,10 +16,6 @@ func connCheck(conn net.Conn) error {
// Reset previous timeout. // Reset previous timeout.
_ = conn.SetDeadline(time.Time{}) _ = conn.SetDeadline(time.Time{})
// Check if tls.Conn.
if c, ok := conn.(*tls.Conn); ok {
conn = c.NetConn()
}
sysConn, ok := conn.(syscall.Conn) sysConn, ok := conn.(syscall.Conn)
if !ok { if !ok {
return nil return nil

View File

@ -3,7 +3,6 @@
package pool package pool
import ( import (
"crypto/tls"
"net" "net"
"net/http/httptest" "net/http/httptest"
"time" "time"
@ -15,17 +14,12 @@ import (
var _ = Describe("tests conn_check with real conns", func() { var _ = Describe("tests conn_check with real conns", func() {
var ts *httptest.Server var ts *httptest.Server
var conn net.Conn var conn net.Conn
var tlsConn *tls.Conn
var err error var err error
BeforeEach(func() { BeforeEach(func() {
ts = httptest.NewServer(nil) ts = httptest.NewServer(nil)
conn, err = net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second) conn, err = net.DialTimeout(ts.Listener.Addr().Network(), ts.Listener.Addr().String(), time.Second)
Expect(err).NotTo(HaveOccurred()) Expect(err).NotTo(HaveOccurred())
tlsTestServer := httptest.NewUnstartedServer(nil)
tlsTestServer.StartTLS()
tlsConn, err = tls.DialWithDialer(&net.Dialer{Timeout: time.Second}, tlsTestServer.Listener.Addr().Network(), tlsTestServer.Listener.Addr().String(), &tls.Config{InsecureSkipVerify: true})
Expect(err).NotTo(HaveOccurred())
}) })
AfterEach(func() { AfterEach(func() {
@ -39,23 +33,11 @@ var _ = Describe("tests conn_check with real conns", func() {
Expect(connCheck(conn)).To(HaveOccurred()) Expect(connCheck(conn)).To(HaveOccurred())
}) })
It("good tls conn check", func() {
Expect(connCheck(tlsConn)).NotTo(HaveOccurred())
Expect(tlsConn.Close()).NotTo(HaveOccurred())
Expect(connCheck(tlsConn)).To(HaveOccurred())
})
It("bad conn check", func() { It("bad conn check", func() {
Expect(conn.Close()).NotTo(HaveOccurred()) Expect(conn.Close()).NotTo(HaveOccurred())
Expect(connCheck(conn)).To(HaveOccurred()) Expect(connCheck(conn)).To(HaveOccurred())
}) })
It("bad tls conn check", func() {
Expect(tlsConn.Close()).NotTo(HaveOccurred())
Expect(connCheck(tlsConn)).To(HaveOccurred())
})
It("check conn deadline", func() { It("check conn deadline", func() {
Expect(conn.SetDeadline(time.Now())).NotTo(HaveOccurred()) Expect(conn.SetDeadline(time.Now())).NotTo(HaveOccurred())
time.Sleep(time.Millisecond * 10) time.Sleep(time.Millisecond * 10)