mirror of
https://github.com/redis/go-redis.git
synced 2025-11-26 06:23:09 +03:00
fix(pool): Pool ReAuth should not interfere with handoff (#3547)
* fix(pool): wip, pool reauth should not interfere with handoff * fix credListeners map * fix race in tests * better conn usable timeout * add design decision comment * few small improvements * update marked as queued * add Used to clarify the state of the conn * rename test * fix(test): fix flaky test * lock inside the listeners collection * address pr comments * Update internal/auth/cred_listeners.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/pool/buffer_size_test.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * wip refactor entraid * fix maintnotif pool hook * fix mocks * fix nil listener * sync and async reauth based on conn lifecycle * be able to reject connection OnGet * pass hooks so the tests can observe reauth * give some time for the background to execute commands * fix tests * only async reauth * Update internal/pool/pool.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/auth/streaming/pool_hook.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update internal/pool/conn.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * chore(redisotel): use metric.WithAttributeSet to avoid copy (#3552) In order to improve performance replace `WithAttributes` with `WithAttributeSet`. This avoids the slice allocation and copy that is done in `WithAttributes`. For more information see https://github.com/open-telemetry/opentelemetry-go/blob/v1.38.0/metric/instrument.go#L357-L376 * chore(docs): explain why MaxRetries is disabled for ClusterClient (#3551) Co-authored-by: Nedyalko Dyakov <1547186+ndyakov@users.noreply.github.com> * exponential backoff * address pr comments * address pr comments * remove rlock * add some comments * add comments --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Warnar Boekkooi <wboekkooi@impossiblecloud.com> Co-authored-by: Justin <justindsouza80@gmail.com>
This commit is contained in:
@@ -3,7 +3,6 @@ package pool_test
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"net"
|
||||
"unsafe"
|
||||
|
||||
. "github.com/bsm/ginkgo/v2"
|
||||
@@ -124,20 +123,26 @@ var _ = Describe("Buffer Size Configuration", func() {
|
||||
})
|
||||
|
||||
// Helper functions to extract buffer sizes using unsafe pointers
|
||||
// The struct layout must match pool.Conn exactly to avoid checkptr violations.
|
||||
// checkptr is Go's pointer safety checker, which ensures that unsafe pointer
|
||||
// conversions are valid. If the struct layouts do not match exactly, this can
|
||||
// cause runtime panics or incorrect memory access due to invalid pointer dereferencing.
|
||||
func getWriterBufSizeUnsafe(cn *pool.Conn) int {
|
||||
cnPtr := (*struct {
|
||||
usedAt int64
|
||||
netConn net.Conn
|
||||
rd *proto.Reader
|
||||
bw *bufio.Writer
|
||||
wr *proto.Writer
|
||||
// ... other fields
|
||||
id uint64 // First field in pool.Conn
|
||||
usedAt int64 // Second field (atomic)
|
||||
netConnAtomic interface{} // atomic.Value (interface{} has same size)
|
||||
rd *proto.Reader
|
||||
bw *bufio.Writer
|
||||
wr *proto.Writer
|
||||
// We only need fields up to bw, so we can stop here
|
||||
})(unsafe.Pointer(cn))
|
||||
|
||||
if cnPtr.bw == nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
// bufio.Writer internal structure
|
||||
bwPtr := (*struct {
|
||||
err error
|
||||
buf []byte
|
||||
@@ -150,18 +155,20 @@ func getWriterBufSizeUnsafe(cn *pool.Conn) int {
|
||||
|
||||
func getReaderBufSizeUnsafe(cn *pool.Conn) int {
|
||||
cnPtr := (*struct {
|
||||
usedAt int64
|
||||
netConn net.Conn
|
||||
rd *proto.Reader
|
||||
bw *bufio.Writer
|
||||
wr *proto.Writer
|
||||
// ... other fields
|
||||
id uint64 // First field in pool.Conn
|
||||
usedAt int64 // Second field (atomic)
|
||||
netConnAtomic interface{} // atomic.Value (interface{} has same size)
|
||||
rd *proto.Reader
|
||||
bw *bufio.Writer
|
||||
wr *proto.Writer
|
||||
// We only need fields up to rd, so we can stop here
|
||||
})(unsafe.Pointer(cn))
|
||||
|
||||
if cnPtr.rd == nil {
|
||||
return -1
|
||||
}
|
||||
|
||||
// proto.Reader internal structure
|
||||
rdPtr := (*struct {
|
||||
rd *bufio.Reader
|
||||
})(unsafe.Pointer(cnPtr.rd))
|
||||
@@ -170,6 +177,7 @@ func getReaderBufSizeUnsafe(cn *pool.Conn) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
// bufio.Reader internal structure
|
||||
bufReaderPtr := (*struct {
|
||||
buf []byte
|
||||
rd interface{}
|
||||
|
||||
Reference in New Issue
Block a user