From b9531bb1ae520b0cbc6c00894623c9abf8dd02c0 Mon Sep 17 00:00:00 2001 From: Michael Contolini Date: Wed, 18 Nov 2020 00:20:26 -0800 Subject: [PATCH] Use poll implementation to fix file descriptor leak Using select() here causes a file descriptor leak. We've replaced this with a poll() implemenetation to avoid this. The polling object needs to be opened with an eventmask that stops it from blocking paramiko. Fixes https://github.com/ploxiln/fab-classic/issues/51 Co-authored-by: Dan Porter --- fabric/io.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fabric/io.py b/fabric/io.py index 3cd4ef42..908dc2e3 100644 --- a/fabric/io.py +++ b/fabric/io.py @@ -2,7 +2,7 @@ import sys import socket import time -from select import select +from select import poll from collections import deque import six @@ -268,8 +268,9 @@ def input_loop(chan, f, using_pty): if msvcrt.kbhit(): byte = msvcrt.getch() elif waitable: - r, w, x = select([f], [], [], 0.0) - if f in r: + poller = poll() + poller.register(f, 1) + if poller.poll(f.fileno()): byte = f.read(1) else: byte = f.read(1)