Use buffered channel for inmemlayer's pendingConns to fix timeout errors (#21098)

Error in question is: `transport: Error while dialing: inmemlayer: timeout while accepting connection`
This commit is contained in:
Nick Cabatoff 2023-07-25 12:02:20 -04:00 committed by GitHub
parent e13ccf9835
commit fd20c99c4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -107,7 +107,7 @@ func (l *InmemLayer) Listeners() []NetworkListener {
l.listener = &inmemListener{
addr: l.addr,
pendingConns: make(chan net.Conn),
pendingConns: make(chan net.Conn, 1),
stopped: atomic.NewBool(false),
stopCh: make(chan struct{}),

View File

@ -27,6 +27,7 @@ func TestInmemCluster_Connect(t *testing.T) {
listener := server.Listeners()[0]
var accepted int
stopCh := make(chan struct{})
defer close(stopCh)
var wg sync.WaitGroup
wg.Add(1)
go func() {
@ -69,7 +70,6 @@ func TestInmemCluster_Connect(t *testing.T) {
t.Fatal("nil conn")
}
close(stopCh)
wg.Wait()
if accepted != 2 {
@ -93,6 +93,7 @@ func TestInmemCluster_Disconnect(t *testing.T) {
listener := server.Listeners()[0]
var accepted int
stopCh := make(chan struct{})
defer close(stopCh)
var wg sync.WaitGroup
wg.Add(1)
go func() {
@ -136,7 +137,6 @@ func TestInmemCluster_Disconnect(t *testing.T) {
t.Fatal("nil conn")
}
close(stopCh)
wg.Wait()
if accepted != 1 {
@ -199,6 +199,8 @@ func TestInmemCluster_ConnectCluster(t *testing.T) {
var accepted atomic.Int32
stopCh := make(chan struct{})
defer close(stopCh)
var wg sync.WaitGroup
acceptConns := func(listener NetworkListener) {
wg.Add(1)
@ -255,7 +257,6 @@ func TestInmemCluster_ConnectCluster(t *testing.T) {
}
}
close(stopCh)
wg.Wait()
if accepted.Load() != 18 {