Rev 3935: Add some EINTR-proofing to smart protocol socket code. (Andrew in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jan 12 05:35:30 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3935
revision-id: pqm at pqm.ubuntu.com-20090112053526-fvc589mub65ppz2m
parent: pqm at pqm.ubuntu.com-20090110235923-dibvaa8suy8gk1ef
parent: andrew.bennetts at canonical.com-20090112042055-n9rzy4ih863bvd4a
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2009-01-12 05:35:26 +0000
message:
  Add some EINTR-proofing to smart protocol socket code. (Andrew
  	Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
  bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
    ------------------------------------------------------------
    revno: 3923.3.4
    revision-id: andrew.bennetts at canonical.com-20090112042055-n9rzy4ih863bvd4a
    parent: andrew.bennetts at canonical.com-20090112041359-sn8hvfz3ou1xityy
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: eintr-safety
    timestamp: Mon 2009-01-12 15:20:55 +1100
    message:
      Add NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3923.3.3
    revision-id: andrew.bennetts at canonical.com-20090112041359-sn8hvfz3ou1xityy
    parent: andrew.bennetts at canonical.com-20090112041314-v8nhwyg3oxpveeup
    parent: pqm at pqm.ubuntu.com-20090109052909-3jh4taiu906vin4p
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: eintr-safety
    timestamp: Mon 2009-01-12 15:13:59 +1100
    message:
      Merge from bzr.dev.
    added:
      bzrlib/plugins/netrc_credential_store/ netrc_credential_sto-20081006090354-oaoid1olhgk8vevm-1
      bzrlib/plugins/netrc_credential_store/__init__.py __init__.py-20081006090402-hd75m8kcrrm0vlz1-1
      bzrlib/plugins/netrc_credential_store/tests/ tests-20081006090406-6mddz8j10pux993e-1
      bzrlib/plugins/netrc_credential_store/tests/__init__.py __init__.py-20081006090411-vytweyz6sun61d4q-1
      bzrlib/plugins/netrc_credential_store/tests/test_netrc.py test_netrc.py-20081006090414-vm3or4tz6c9wk2oi-1
      bzrlib/tests/https_server.py   https_server.py-20071121173708-aj8zczi0ziwbwz21-1
      bzrlib/tests/ssl_certs/        ssl_certs-20071124141654-dc9za9nho2gmzbri-1
      bzrlib/tests/ssl_certs/__init__.py __init__.py-20071124141703-j5hr254lm287lyut-8
      bzrlib/tests/ssl_certs/ca.crt  ca.crt-20071124141703-j5hr254lm287lyut-7
      bzrlib/tests/ssl_certs/ca.key  ca.key-20071124141703-j5hr254lm287lyut-6
      bzrlib/tests/ssl_certs/create_ssls.py create_ssls.py-20071124141703-j5hr254lm287lyut-5
      bzrlib/tests/ssl_certs/server.crt server.crt-20071124141703-j5hr254lm287lyut-4
      bzrlib/tests/ssl_certs/server.csr server.csr-20071124141703-j5hr254lm287lyut-3
      bzrlib/tests/ssl_certs/server_with_pass.key server_with_pass.key-20071124141703-j5hr254lm287lyut-2
      bzrlib/tests/ssl_certs/server_without_pass.key server_without_pass.-20071124141703-j5hr254lm287lyut-1
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
      bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
      bzrlib/builtins.py             builtins.py-20050830033751-fc01482b9ca23183
      bzrlib/bzrdir.py               bzrdir.py-20060131065624-156dfea39c4387cb
      bzrlib/config.py               config.py-20051011043216-070c74f4e9e338e8
      bzrlib/dirstate.py             dirstate.py-20060728012006-d6mvoihjb3je9peu-1
      bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
      bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
      bzrlib/knit.py                 knit.py-20051212171256-f056ac8f0fbe1bd9
      bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
      bzrlib/mail_client.py          mail_client.py-20070809192806-vuxt3t19srtpjpdn-1
      bzrlib/push.py                 push.py-20080606021927-5fe39050e8xne9un-1
      bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
      bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
      bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
      bzrlib/tests/branch_implementations/test_stacking.py test_stacking.py-20080214020755-msjlkb7urobwly0f-1
      bzrlib/tests/commands/test_push.py test_push.py-20070525122003-gc1ob0ea0nueoqgj-1
      bzrlib/tests/http_server.py    httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
      bzrlib/tests/test_bzrdir.py    test_bzrdir.py-20060131065654-deba40eef51cf220
      bzrlib/tests/test_config.py    testconfig.py-20051011041908-742d0c15d8d8c8eb
      bzrlib/tests/test_http.py      testhttp.py-20051018020158-b2eef6e867c514d9
      bzrlib/tests/test_log.py       testlog.py-20050728115707-1a514809d7d49309
      bzrlib/tests/test_mail_client.py test_mail_client.py-20070809192806-vuxt3t19srtpjpdn-2
      bzrlib/tests/test_plugins.py   plugins.py-20050622075746-32002b55e5e943e9
      bzrlib/tests/workingtree_implementations/test_move.py test_move.py-20070225171927-mohn2vqj5fx7edc6-1
      bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
      bzrlib/transport/ftp/__init__.py ftp.py-20051116161804-58dc9506548c2a53
      bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
      bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
      bzrlib/transport/http/ca_bundle.py ca_bundle.py-20070226091335-84kb1xg1r2jjf858-1
      doc/developers/authentication-ring.txt authring.txt-20070718200437-q5tdik0ne6lor86d-1
    ------------------------------------------------------------
    revno: 3923.3.2
    revision-id: andrew.bennetts at canonical.com-20090112041314-v8nhwyg3oxpveeup
    parent: andrew.bennetts at canonical.com-20090107005830-ua1dmtrnyl37acf4
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: eintr-safety
    timestamp: Mon 2009-01-12 15:13:14 +1100
    message:
      Use e.errno rather than e.args[0].
    modified:
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
    ------------------------------------------------------------
    revno: 3923.3.1
    revision-id: andrew.bennetts at canonical.com-20090107005830-ua1dmtrnyl37acf4
    parent: pqm at pqm.ubuntu.com-20090106171520-9pzjoqa7m74hvhht
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: eintr-safety
    timestamp: Wed 2009-01-07 11:58:30 +1100
    message:
      Quick attempt at adding some EINTR-proofing to smart protocol code.
    modified:
      bzrlib/osutils.py              osutils.py-20050309040759-eeaff12fbf77ac86
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
=== modified file 'NEWS'
--- a/NEWS	2009-01-09 05:29:09 +0000
+++ b/NEWS	2009-01-12 04:20:55 +0000
@@ -90,6 +90,11 @@
       in the appropriate sections.
       (Vincent Ladeuil, #103029)
 
+    * Many socket operations now handle EINTR by retrying the operation.
+      Previously EINTR was treated as an unrecoverable failure.  There is
+      a new ``until_no_eintr`` helper function in ``bzrlib.osutils``.
+      (Andrew Bennetts)
+
     * Opening a stacked branch now properly shares the connection, rather
       than opening a new connection for the stacked-on branch.
       (John Arbash meinel)

=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py	2008-12-12 14:33:13 +0000
+++ b/bzrlib/osutils.py	2009-01-12 04:13:59 +0000
@@ -1549,7 +1549,7 @@
     """
     b = ''
     while len(b) < bytes:
-        new = socket.recv(bytes - len(b))
+        new = until_no_eintr(socket.recv, bytes - len(b))
         if new == '':
             break # eof
         b += new
@@ -1564,7 +1564,7 @@
     """
     chunk_size = 2**16
     for pos in xrange(0, len(bytes), chunk_size):
-        socket.sendall(bytes[pos:pos+chunk_size])
+        until_no_eintr(socket.sendall, bytes[pos:pos+chunk_size])
 
 
 def dereference_path(path):
@@ -1637,6 +1637,19 @@
             raise errors.NoSuchFile(f)
         raise
 
+
+def until_no_eintr(f, *a, **kw):
+    """Run f(*a, **kw), retrying if an EINTR error occurs."""
+    # Borrowed from Twisted's twisted.python.util.untilConcludes function.
+    while True:
+        try:
+            return f(*a, **kw)
+        except (IOError, OSError), e:
+            if e.errno == errno.EINTR:
+                continue
+            raise
+
+
 if sys.platform == "win32":
     import msvcrt
     def getchar():

=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2008-10-02 13:25:47 +0000
+++ b/bzrlib/smart/medium.py	2009-01-07 00:58:30 +0000
@@ -274,7 +274,7 @@
     def _read_bytes(self, desired_count):
         # We ignore the desired_count because on sockets it's more efficient to
         # read large chunks (of _MAX_READ_SIZE bytes) at a time.
-        return self.socket.recv(_MAX_READ_SIZE)
+        return osutils.until_no_eintr(self.socket.recv, _MAX_READ_SIZE)
 
     def terminate_due_to_error(self):
         # TODO: This should log to a server log file, but no such thing




More information about the bazaar-commits mailing list