Fix iter_read() FD leaks on 3.x; closes #418.

issue510
David Wilson 6 years ago
parent 3f46c9569c
commit 045db6f689

@ -80,12 +80,7 @@ class Stream(mitogen.parent.Stream):
password_incorrect_msg = 'doas password is incorrect' password_incorrect_msg = 'doas password is incorrect'
password_required_msg = 'doas password is required' password_required_msg = 'doas password is required'
def _connect_bootstrap(self): def _connect_input_loop(self, it):
it = mitogen.parent.iter_read(
fds=[self.receive_side.fd, self.diag_stream.receive_side.fd],
deadline=self.connect_deadline,
)
password_sent = False password_sent = False
for buf in it: for buf in it:
LOG.debug('%r: received %r', self, buf) LOG.debug('%r: received %r', self, buf)
@ -106,3 +101,13 @@ class Stream(mitogen.parent.Stream):
) )
password_sent = True password_sent = True
raise mitogen.core.StreamError('bootstrap failed') raise mitogen.core.StreamError('bootstrap failed')
def _connect_bootstrap(self):
it = mitogen.parent.iter_read(
fds=[self.receive_side.fd, self.diag_stream.receive_side.fd],
deadline=self.connect_deadline,
)
try:
self._connect_input_loop(it)
finally:
it.close()

@ -532,12 +532,16 @@ def discard_until(fd, s, deadline):
:raises mitogen.core.StreamError: :raises mitogen.core.StreamError:
Attempt to read past end of file. Attempt to read past end of file.
""" """
for buf in iter_read([fd], deadline): it = iter_read([fd], deadline)
if IOLOG.level == logging.DEBUG: try:
for line in buf.splitlines(): for buf in it:
IOLOG.debug('discard_until: discarding %r', line) if IOLOG.level == logging.DEBUG:
if buf.endswith(s): for line in buf.splitlines():
return IOLOG.debug('discard_until: discarding %r', line)
if buf.endswith(s):
return
finally:
it.close() # ensure Poller.close() is called.
def _upgrade_broker(broker): def _upgrade_broker(broker):

@ -264,13 +264,7 @@ class Stream(mitogen.parent.Stream):
# with ours. # with ours.
raise HostKeyError(self.hostkey_config_msg) raise HostKeyError(self.hostkey_config_msg)
def _connect_bootstrap(self): def _connect_input_loop(self, it):
fds = [self.receive_side.fd]
if self.diag_stream is not None:
fds.append(self.diag_stream.receive_side.fd)
it = mitogen.parent.iter_read(fds=fds, deadline=self.connect_deadline)
password_sent = False password_sent = False
for buf, partial in filter_debug(self, it): for buf, partial in filter_debug(self, it):
LOG.debug('%r: received %r', self, buf) LOG.debug('%r: received %r', self, buf)
@ -302,3 +296,14 @@ class Stream(mitogen.parent.Stream):
password_sent = True password_sent = True
raise mitogen.core.StreamError('bootstrap failed') raise mitogen.core.StreamError('bootstrap failed')
def _connect_bootstrap(self):
fds = [self.receive_side.fd]
if self.diag_stream is not None:
fds.append(self.diag_stream.receive_side.fd)
it = mitogen.parent.iter_read(fds=fds, deadline=self.connect_deadline)
try:
self._connect_input_loop(it)
finally:
it.close()

@ -87,13 +87,7 @@ class Stream(mitogen.parent.Stream):
password_incorrect_msg = 'su password is incorrect' password_incorrect_msg = 'su password is incorrect'
password_required_msg = 'su password is required' password_required_msg = 'su password is required'
def _connect_bootstrap(self): def _connect_input_loop(self, it):
password_sent = False
it = mitogen.parent.iter_read(
fds=[self.receive_side.fd],
deadline=self.connect_deadline,
)
for buf in it: for buf in it:
LOG.debug('%r: received %r', self, buf) LOG.debug('%r: received %r', self, buf)
if buf.endswith(self.EC0_MARKER): if buf.endswith(self.EC0_MARKER):
@ -113,3 +107,14 @@ class Stream(mitogen.parent.Stream):
) )
password_sent = True password_sent = True
raise mitogen.core.StreamError('bootstrap failed') raise mitogen.core.StreamError('bootstrap failed')
def _connect_bootstrap(self):
password_sent = False
it = mitogen.parent.iter_read(
fds=[self.receive_side.fd],
deadline=self.connect_deadline,
)
try:
self._connect_input_loop(it)
finally:
it.close()

@ -173,17 +173,7 @@ class Stream(mitogen.parent.Stream):
password_incorrect_msg = 'sudo password is incorrect' password_incorrect_msg = 'sudo password is incorrect'
password_required_msg = 'sudo password is required' password_required_msg = 'sudo password is required'
def _connect_bootstrap(self): def _connect_input_loop(self, it):
fds = [self.receive_side.fd]
if self.diag_stream is not None:
fds.append(self.diag_stream.receive_side.fd)
password_sent = False
it = mitogen.parent.iter_read(
fds=fds,
deadline=self.connect_deadline,
)
for buf in it: for buf in it:
LOG.debug('%r: received %r', self, buf) LOG.debug('%r: received %r', self, buf)
if buf.endswith(self.EC0_MARKER): if buf.endswith(self.EC0_MARKER):
@ -199,3 +189,19 @@ class Stream(mitogen.parent.Stream):
) )
password_sent = True password_sent = True
raise mitogen.core.StreamError('bootstrap failed') raise mitogen.core.StreamError('bootstrap failed')
def _connect_bootstrap(self):
fds = [self.receive_side.fd]
if self.diag_stream is not None:
fds.append(self.diag_stream.receive_side.fd)
password_sent = False
it = mitogen.parent.iter_read(
fds=fds,
deadline=self.connect_deadline,
)
try:
self._connect_input_loop(it)
finally:
it.close()

Loading…
Cancel
Save