Patchwork D12628: worker: fix `_blockingreader.read()` to really block

login
register
mail settings
Submitter phabricator
Date May 18, 2022, 4:36 p.m.
Message ID <differential-rev-PHID-DREV-565b3qqew7gbcqyozxnj-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/50981/
State New
Headers show

Comments

phabricator - May 18, 2022, 4:36 p.m.
mharbison72 created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Maybe I'm missing something simple, but the help for `io.BytesIO.readinto` says:
  
    Returns number of bytes read (0 for EOF), or None if the object
    is set not to block and has no data to read.
  
  and `io.BytesIO.read` says:
  
    Return an empty bytes object at EOF.
  
  That would seem to mean that if the _first_ internal `readinto()` of the
  nonblocking `self._wrapped` returns `None` because no data is available, the caller
  is tricked that EOF has been reached by returning an empty bytes object.

REPOSITORY
  rHG Mercurial

BRANCH
  stable

REVISION DETAIL
  https://phab.mercurial-scm.org/D12628

AFFECTED FILES
  mercurial/worker.py

CHANGE DETAILS




To: mharbison72, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/worker.py b/mercurial/worker.py
--- a/mercurial/worker.py
+++ b/mercurial/worker.py
@@ -109,8 +109,10 @@ 
 
             while pos < size:
                 ret = self._wrapped.readinto(view[pos:])
-                if not ret:
-                    break
+                if ret is None:
+                    continue  # nonblocking, and no data
+                elif ret == 0:
+                    break  # 0 -> EOF
                 pos += ret
 
             del view