public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/remote/
Date: Sat, 15 Feb 2014 19:49:52 +0000 (UTC)	[thread overview]
Message-ID: <1392492760.090836adcae4aafa03baa199c44e06c5691bf647.dywi@gentoo> (raw)

commit:     090836adcae4aafa03baa199c44e06c5691bf647
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Sat Feb 15 19:23:30 2014 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Sat Feb 15 19:32:40 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=090836ad

roverlay/remote/websync: handle connection timeouts

Wait up to URLOPEN_TIMEOUT(=10) seconds before giving up (and setting
want_retry). The timeout value cannot be changed in the config file.

---
 roverlay/remote/websync.py | 60 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 48 insertions(+), 12 deletions(-)

diff --git a/roverlay/remote/websync.py b/roverlay/remote/websync.py
index 86f4d48..cbad78d 100644
--- a/roverlay/remote/websync.py
+++ b/roverlay/remote/websync.py
@@ -14,6 +14,7 @@ import errno
 import contextlib
 import re
 import os
+import socket
 import sys
 
 # py2 urllib2 vs py3 urllib.request
@@ -38,6 +39,9 @@ from roverlay.remote.basicrepo import BasicRepo
 #
 MAX_WEBSYNC_RETRY = 3
 
+# timeout for urlopen, in seconds
+URLOPEN_TIMEOUT = 10
+
 VERBOSE = True
 
 # FIXME: websync does not support package deletion
@@ -48,6 +52,7 @@ class WebsyncBase ( BasicRepo ):
 
    HTTP_ERROR_RETRY_CODES = frozenset ({ 404, 410, 500, 503 })
    URL_ERROR_RETRY_CODES  = frozenset ({ errno.ETIMEDOUT, })
+   RETRY_ON_TIMEOUT       = True
 
    def __init__ ( self,
       name,
@@ -118,7 +123,9 @@ class WebsyncBase ( BasicRepo ):
          return True
 
 
-      with contextlib.closing ( urlopen ( src_uri ) ) as webh:
+      with contextlib.closing (
+         urlopen ( src_uri, None, URLOPEN_TIMEOUT )
+      ) as webh:
          #web_info = webh.info()
 
          expected_filesize = int ( webh.info().get ( 'content-length', -1 ) )
@@ -296,18 +303,44 @@ class WebsyncBase ( BasicRepo ):
                #break
 
          except URLError as err:
-            if err.reason.errno in self.URL_ERROR_RETRY_CODES:
-               self.logger.info (
-                  'sync failed with an url error (errno {:d}). '
-                  'Retrying...'.format ( err.reason.errno )
-               )
+            if isinstance ( err.reason, socket.timeout ):
+               if self.RETRY_ON_TIMEOUT:
+                  self.logger.info ( 'Connection timed out (#1). Retrying...' )
+                  want_retry = True
+               else:
+                  self.logger.error ( 'Connection timed out (#1).' )
+                  self.logger.exception ( err )
+                  retval = False
+                  #break
+
+            elif hasattr ( err.reason, 'errno' ):
+               if err.reason.errno in self.URL_ERROR_RETRY_CODES:
+                  self.logger.info (
+                     'sync failed with an url error (errno {:d}). '
+                     'Retrying...'.format ( err.reason.errno )
+                  )
+                  want_retry = True
+               else:
+                  self.logger.error (
+                     "got an unexpected url error code: {:d}".format (
+                        err.reason.errno
+                     )
+                  )
+                  self.logger.exception ( err )
+                  retval = False
+                  #break
+            else:
+               self.logger.error ( "got an unexpected url error." )
+               self.logger.exception ( err )
+               retval = False
+               #break
+
+         except socket.timeout as err:
+            if self.RETRY_ON_TIMEOUT:
+               self.logger.info ( 'Connection timed out (#2). Retrying...' )
                want_retry = True
             else:
-               self.logger.error (
-                  "got an unexpected url error code: {:d}".format (
-                     err.reason.errno
-                  )
-               )
+               self.logger.error ( 'Connection timed out (#2).' )
                self.logger.exception ( err )
                retval = False
                #break
@@ -315,6 +348,7 @@ class WebsyncBase ( BasicRepo ):
          except KeyboardInterrupt:
             #sys.stderr.write ( "\nKeyboard Interrupt\n" )
             #if RERAISE_INTERRUPT ...
+            #retval = False
             raise
 
          except Exception as err:
@@ -327,13 +361,13 @@ class WebsyncBase ( BasicRepo ):
       # -- end while
 
       if retval is None:
-         assert max_retry < 0
          self.logger.error (
             'Repo {name} cannot be used for ebuild creation: '
             'did not try to sync (max_retry={max_retry:d})'.format (
                name=self.name, max_retry=max_retry
             )
          )
+         return False
 
       elif want_retry:
          self.logger.error (
@@ -341,8 +375,10 @@ class WebsyncBase ( BasicRepo ):
             'retry count exhausted.'.format ( name=self.name )
          )
          return False
+
       elif retval:
          return True
+
       else:
          self.logger.error (
             'Repo {name} cannot be used for ebuild creation due to errors '


             reply	other threads:[~2014-02-15 19:50 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-15 19:49 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-01-26 17:41 [gentoo-commits] proj/R_overlay:master commit in: roverlay/remote/ André Erdmann
2014-02-16 16:45 André Erdmann
2014-02-15 19:49 André Erdmann
2014-02-15 19:49 André Erdmann
2013-09-03 13:15 André Erdmann
2013-09-03  8:35 André Erdmann
2013-09-02 16:21 André Erdmann
2013-08-29 15:08 André Erdmann
2013-08-07 16:10 André Erdmann
2013-08-07 16:10 André Erdmann
2013-07-24  9:54 André Erdmann
2013-07-24  9:54 André Erdmann
2013-07-24  9:54 André Erdmann
2013-07-23 14:57 André Erdmann
2013-07-23  9:38 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 14:57 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-23  9:38 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23 14:57 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-16 16:35 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-16 16:36 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-08-13 18:07 André Erdmann
2012-08-11  0:01 André Erdmann
2012-08-10 15:16 André Erdmann
2012-08-10 15:16 André Erdmann
2012-08-09  9:26 André Erdmann
2012-08-02 15:14 André Erdmann
2012-08-01  7:33 André Erdmann
2012-07-31 17:51 André Erdmann
2012-07-09 17:25 André Erdmann
2012-07-06  8:15 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-27 14:46 André Erdmann
2012-06-26 15:55 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-25 18:19 André Erdmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392492760.090836adcae4aafa03baa199c44e06c5691bf647.dywi@gentoo \
    --to=dywi@mailerd.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox