public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH] AbstractPollTask._read_buf: read regardless of event flags (531724)
@ 2014-12-26  9:00 Zac Medico
  2015-01-05 12:52 ` Alexander Berntsen
  0 siblings, 1 reply; 2+ messages in thread
From: Zac Medico @ 2014-12-26  9:00 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

PipeReaderPtyTestCase shows that data may be lost unless we attempt to
read data for every poll event, regardless of the event flags.

Therefore, always read, regardless of the event flags. This is safe to
do because all consumers of this API use non-blocking mode and properly
handle EAGAIN (signaled when this method returns None).

X-Gentoo-Bug: 531724
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=531724
---
 pym/_emerge/AbstractPollTask.py | 50 +++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 22 deletions(-)

diff --git a/pym/_emerge/AbstractPollTask.py b/pym/_emerge/AbstractPollTask.py
index 3f6dd6c..48e7590 100644
--- a/pym/_emerge/AbstractPollTask.py
+++ b/pym/_emerge/AbstractPollTask.py
@@ -78,33 +78,39 @@ class AbstractPollTask(AsynchronousTask):
 
 	def _read_buf(self, fd, event):
 		"""
-		| POLLIN | RETURN
-		| BIT    | VALUE
-		| ---------------------------------------------------
-		| 1      | Read self._bufsize into a string of bytes,
-		|        | handling EAGAIN and EIO. An empty string
-		|        | of bytes indicates EOF.
-		| ---------------------------------------------------
-		| 0      | None
+		Read self._bufsize into a string of bytes, handling EAGAIN and
+		EIO. This will only call os.read() once, so the caller should
+		call this method in a loop until either None or an empty string
+		of bytes is returned. An empty string of bytes indicates EOF.
+		None indicates EAGAIN.
+
+		NOTE: os.read() will be called regardless of the event flags,
+			since otherwise data may be lost (see bug #531724).
+
+		@param fd: file descriptor (non-blocking mode required)
+		@type fd: int
+		@param event: poll event flags
+		@type event: int
+		@rtype: bytes or None
+		@return: A string of bytes, or None
 		"""
 		# NOTE: array.fromfile() is no longer used here because it has
 		# bugs in all known versions of Python (including Python 2.7
 		# and Python 3.2).
 		buf = None
-		if event & self.scheduler.IO_IN:
-			try:
-				buf = os.read(fd, self._bufsize)
-			except OSError as e:
-				# EIO happens with pty on Linux after the
-				# slave end of the pty has been closed.
-				if e.errno == errno.EIO:
-					# EOF: return empty string of bytes
-					buf = b''
-				elif e.errno == errno.EAGAIN:
-					# EAGAIN: return None
-					buf = None
-				else:
-					raise
+		try:
+			buf = os.read(fd, self._bufsize)
+		except OSError as e:
+			# EIO happens with pty on Linux after the
+			# slave end of the pty has been closed.
+			if e.errno == errno.EIO:
+				# EOF: return empty string of bytes
+				buf = b''
+			elif e.errno == errno.EAGAIN:
+				# EAGAIN: return None
+				buf = None
+			else:
+				raise
 
 		return buf
 
-- 
2.0.5



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-portage-dev] [PATCH] AbstractPollTask._read_buf: read regardless of event flags (531724)
  2014-12-26  9:00 [gentoo-portage-dev] [PATCH] AbstractPollTask._read_buf: read regardless of event flags (531724) Zac Medico
@ 2015-01-05 12:52 ` Alexander Berntsen
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Berntsen @ 2015-01-05 12:52 UTC (permalink / raw
  To: gentoo-portage-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

LGTM, go ahead & merge.

- -- 
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iF4EAREIAAYFAlSqiRYACgkQRtClrXBQc7V+SQD+MJZbpHv/Iy3KZ2BYp2snZ3jS
GQbL36eeDSsNz3G2Y+0A/16ZEx8N4FtF6E9vwbpJYwPdC6vS109ZI3VCI9ahWZ0Z
=eQqK
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-05 12:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-26  9:00 [gentoo-portage-dev] [PATCH] AbstractPollTask._read_buf: read regardless of event flags (531724) Zac Medico
2015-01-05 12:52 ` Alexander Berntsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox