Skip to content

Commit

Permalink
fix: dial timeout panic
Browse files Browse the repository at this point in the history
  • Loading branch information
joway committed Oct 12, 2023
1 parent cf96b81 commit f04dada
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"net"
"os"
"runtime"
"strings"
"sync"
"sync/atomic"
"syscall"
Expand Down Expand Up @@ -638,3 +639,36 @@ func TestConnectionServerClose(t *testing.T) {
//time.Sleep(time.Second)
wg.Wait()
}

func TestConnectionDailTimeoutAndClose(t *testing.T) {
ln, err := createTestListener("tcp", ":12345")
MustNil(t, err)
defer ln.Close()

el, err := NewEventLoop(
func(ctx context.Context, connection Connection) error {
_, err = connection.Reader().Next(connection.Reader().Len())
return err
},
)
defer el.Shutdown(context.Background())
go func() {
err := el.Serve(ln)
if err != nil {
t.Logf("servce end with error: %v", err)
}
}()

conns := 100
var wg sync.WaitGroup
wg.Add(conns)
for i := 0; i < conns; i++ {
go func() {
defer wg.Done()
conn, err := DialConnection("tcp", ":12345", time.Nanosecond)
Assert(t, strings.Contains(err.Error(), "i/o timeout") || err == nil)
_ = conn
}()
}
wg.Wait()
}

0 comments on commit f04dada

Please sign in to comment.