Skip to content

Commit 6d650bb

Browse files
Merge pull request #9 from orkunkaraduman/develop
v1.2.2
2 parents 3b862d2 + 70eac7b commit 6d650bb

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

accepter.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"crypto/tls"
77
"net"
88
"sync"
9-
"sync/atomic"
109
"time"
1110
)
1211

@@ -19,9 +18,6 @@ type Accepter struct {
1918
// TLSConfig optionally provides a TLS configuration.
2019
TLSConfig *tls.Config
2120

22-
// TemporaryErrorCount increments each temporary accept error
23-
TemporaryErrorCount uint64
24-
2521
lis net.Listener
2622
lisCloseOnce *sync.Once
2723
lisCloseErr error
@@ -131,6 +127,7 @@ func (a *Accepter) Serve(lis net.Listener) (err error) {
131127
a.ctx, a.ctxCancel = context.WithCancel(context.Background())
132128
defer a.ctxCancel()
133129
a.conns = make(map[net.Conn]struct{})
130+
var tempDelay time.Duration
134131
for {
135132
var conn net.Conn
136133
conn, err = lis.Accept()
@@ -142,12 +139,20 @@ func (a *Accepter) Serve(lis net.Listener) (err error) {
142139
default:
143140
}
144141
if ne, ok := err.(net.Error); ok && ne.Temporary() {
145-
atomic.AddUint64(&a.TemporaryErrorCount, 1)
146-
time.Sleep(5 * time.Millisecond)
142+
if tempDelay == 0 {
143+
tempDelay = 5 * time.Millisecond
144+
} else {
145+
tempDelay *= 2
146+
}
147+
if max := 1 * time.Second; tempDelay > max {
148+
tempDelay = max
149+
}
150+
time.Sleep(tempDelay)
147151
continue
148152
}
149153
return
150154
}
155+
tempDelay = 0
151156
go a.serve(conn)
152157
}
153158
}

0 commit comments

Comments
 (0)