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

Help Wanted: smbclient.register_session periodically taking > 1 min to create connection #176

Open
MacHu-GWU opened this issue Apr 26, 2022 · 2 comments

Comments

@MacHu-GWU
Copy link

Hi @jborean93, first I appreciate you created this awesome library!

I find out that after around 10 - 15 minutes every time I created a session with smbclient.register_session to the same server, the next session takes like 1 minutes to create. In average it only takes 1~2 seconds.

The server we are using is AWS FSx Windows Server, and I close the connection everytime I finish the job. I think I understand how you implement the cache. However I am not running a long running script. I am like run a python script then go, and run another one (they all have some SMBclient read / write logic). I don't think the cache are used between different python script.py. Also I don't think there would be lots of open connection on the server side since I close those connection after the work.

Any Idea how it happens? Thank you again for this awesome library.

ses = smbclient.register_session(...)
# do something
ses.connection.disconnect()
@jborean93
Copy link
Owner

Sorry for the delay in the reply. I'm unsure as to why this is happening. It sounds like it might be trying to close down the existing connection that might be broken and causing a long time to disconnect. If you are calling ses.connection.disconnect() it will be manually disconnecting the connection but the pool doesn't have any idea that has happened so it fails to remove it from the pool. The next subsequent connection will attempt to revive the connection.

I'll have to find some time to try and play around with it some more and see if I can reproduce the problem. For now I would recommend avoiding manually disconnecting the connection through the session object. If you wish to do it then disconnect the entire pool through smbclient.reset_connection_cache().

import smbclient

smbclient.register_session(...)
...

smbclient.reset_connection_cache()

Or if you wish to keep control over what is being reset you can use a specific cache.

import smbclient

server_cache = {}
smbclient.register_session(..., connection_cache=server_cache)

smbclient.listdir(..., connection_cache=server_cache)
...

smbclient.reset_connection_cache(connection_cache=server_cache)

The downside of the latter approach is you need to specify the cache everytime you do an operation on the server requested.

@MacHu-GWU
Copy link
Author

@jborean93 it does help! Thank you for your reply!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants