From 1572393f46ee80448367c14395ee2083359bc0bf Mon Sep 17 00:00:00 2001 From: Leonard Han Date: Mon, 19 Aug 2024 22:40:43 +0300 Subject: [PATCH] Customizable receive timeout for SMB Connection (#285) * Added customizable receive timeout for SMB Connection * Refactored customizable receive timeout as experimental environment variable --- src/smbprotocol/connection.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/smbprotocol/connection.py b/src/smbprotocol/connection.py index 2c05b9d..da41081 100644 --- a/src/smbprotocol/connection.py +++ b/src/smbprotocol/connection.py @@ -749,6 +749,9 @@ def __init__(self, guid, server_name, port=445, require_signing=True): self.port = port self.transport = None # Instanciated in .connect() + # Experimental customizable value. Might be removed in the future + self._receive_timeout = int(os.environ.get("SMB_EXPERIMENTAL_TRANSPORT_RECEIVE_TIMEOUT", 600)) + # Table of Session entries, the order is important for smbclient. self.session_table = OrderedDict() @@ -1306,7 +1309,7 @@ def _process_message_thread(self): # safe choice. # https://github.com/jborean93/smbprotocol/issues/31 try: - b_msg = self.transport.recv(600) + b_msg = self.transport.recv(self._receive_timeout) except TimeoutError as ex: # Check if the connection has unanswered keepalive echo requests with the reserved field set. # When unanswered keep alive echo exists, the server did not respond withing two times the timeout.