Skip to content

Commit

Permalink
Customizable receive timeout for SMB Connection (#285)
Browse files Browse the repository at this point in the history
* Added customizable receive timeout for SMB Connection

* Refactored customizable receive timeout as experimental environment variable
  • Loading branch information
leonnis12 authored Aug 19, 2024
1 parent 2ce49ef commit 1572393
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/smbprotocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 1572393

Please sign in to comment.