Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default timeout on connection.receive() #257

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/smbclient/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def dfs_request(tree: TreeConnect, path: str) -> DFSReferralResponse:
return dfs_response


def delete_session(server, port=445, connection_cache=None):
def delete_session(server, port=445, connection_cache=None, timeout=60):
"""
Deletes the connection in the connection pool for the server specified. This will also close all sessions
associated with the connection.
Expand All @@ -226,7 +226,7 @@ def delete_session(server, port=445, connection_cache=None):
connection = connection_cache.get(connection_key, None)
if connection:
del connection_cache[connection_key]
connection.disconnect(close=True)
connection.disconnect(close=True, timeout=timeout)


def get_smb_tree(
Expand Down
4 changes: 2 additions & 2 deletions src/smbprotocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ def connect(self, dialect=None, timeout=60, preferred_encryption_algos=None, pre
elif context_type == NegotiateContextType.SMB2_SIGNING_CAPABILITIES:
self.signing_algorithm_id = context["data"]["signing_algorithms"][0]

def disconnect(self, close=True):
def disconnect(self, close=True, timeout=None):
"""
Closes the connection as well as logs off any of the
Disconnects the TCP connection and shuts down the socket listener
Expand All @@ -943,7 +943,7 @@ def disconnect(self, close=True):
# We cannot close the session or tree if the socket has been closed.
if close and self.transport.connected:
for session in list(self.session_table.values()):
session.disconnect(True)
session.disconnect(True, timeout=timeout)

log.info("Disconnecting transport connection")
self.transport.close()
Expand Down
4 changes: 2 additions & 2 deletions src/smbprotocol/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def connect(self):
log.info("Verifying the SMB Setup Session signature as auth is successful")
self.connection.verify_signature(response, self.session_id, force=True)

def disconnect(self, close=True):
def disconnect(self, close=True, timeout=None):
"""
Logs off the session

Expand All @@ -418,7 +418,7 @@ def disconnect(self, close=True):
request = self.connection.send(logoff, sid=self.session_id)

log.info("Session: %s - Receiving Logoff response", self.username)
res = self.connection.receive(request)
res = self.connection.receive(request, timeout=timeout)
res_logoff = SMB2Logoff()
res_logoff.unpack(res["data"].get_value())
log.debug(res_logoff)
Expand Down