]> git.lizzy.rs Git - go-anidb.git/commitdiff
anidb: Wait longer after each UDP API timeout
authorDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Mon, 15 Jul 2013 03:27:04 +0000 (00:27 -0300)
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>
Mon, 15 Jul 2013 03:27:04 +0000 (00:27 -0300)
Reset the wait after the first successful read.

udp.go

diff --git a/udp.go b/udp.go
index df320041a6dd208bfd1a6df110ca7531adf61579..84cd5c8124b0c0ad3b6e2f73e37c591738f4d4e9 100644 (file)
--- a/udp.go
+++ b/udp.go
@@ -96,21 +96,28 @@ func (r *bannedAPIReply) Error() error {
 var bannedReply udpapi.APIReply = &bannedAPIReply{}
 
 func (udp *udpWrap) sendQueue() {
+       initialWait := 6 * time.Second
+       wait := initialWait
        for set := range udp.sendQueueCh {
+       Retry:
                reply := <-udp.AniDBUDP.SendRecv(set.cmd, udpapi.ParamMap(set.params))
 
                if reply.Error() == udpapi.TimeoutError {
                        // retry
-                       go func(set paramSet) { udp.sendQueueCh <- set }(set)
-                       continue
+                       wait = (wait * 15) / 10
+                       if wait > time.Minute {
+                               wait = time.Minute
+                       }
+                       time.Sleep(wait)
+                       goto Retry
                }
+               wait = initialWait
 
                switch reply.Code() {
                case 403, 501, 506: // not logged in, or session expired
                        if err := udp.ReAuth(); err == nil {
                                // retry
-                               go func(set paramSet) { udp.sendQueueCh <- set }(set)
-                               continue
+                               goto Retry
                        }
                case 503, 504: // client library rejected
                        panic(reply.Error())