1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

Merge pull request #69 from jelmersnoeck/fix-accept-return

HTTPTransport: implement queue for listener.
This commit is contained in:
Asim Aslam 2016-04-01 13:39:38 +01:00
commit de2f407e3d

View File

@ -8,12 +8,14 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time"
mls "github.com/micro/misc/lib/tls" mls "github.com/micro/misc/lib/tls"
) )
@ -309,9 +311,23 @@ func (h *httpTransportListener) Close() error {
} }
func (h *httpTransportListener) Accept(fn func(Socket)) error { func (h *httpTransportListener) Accept(fn func(Socket)) error {
var tempDelay time.Duration
for { for {
c, err := h.listener.Accept() c, err := h.listener.Accept()
if err != nil { if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
if tempDelay == 0 {
tempDelay = 5 * time.Millisecond
} else {
tempDelay *= 2
}
if max := 1 * time.Second; tempDelay > max {
tempDelay = max
}
log.Printf("http: Accept error: %v; retrying in %v\n", err, tempDelay)
time.Sleep(tempDelay)
continue
}
return err return err
} }