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

Question about connections and sessions reuse #808

Open
proxymus89 opened this issue Jan 22, 2024 · 4 comments
Open

Question about connections and sessions reuse #808

proxymus89 opened this issue Jan 22, 2024 · 4 comments

Comments

@proxymus89
Copy link

Hi, I have a multi thread application with a single instance of SMBJ client. For every operation (download, upload, list, etc.) the program calls

connection = client.connect(rootAddress);
session = connection.authenticate(authContext);

the problem is that i see that the library reuse correctly the connection from the cache but not the session.

for example, if it calls 20 operations after these operations I will always have only one connection object (which it retrieves from the cache each time) while the sessionTable will be populated by 20 sessions (but I would expect only one)

So my question are:

  1. is correct my approach to call every time the "connection.authenticate(authContext)"?if yes, why it doesn't reuse allways the same session but creates every time a new one?

  2. if i don't close manually the connection and the session, they remain alive forever?exists a timeout?and how to set it? (the timeout in SmbConfig seems to be a different thing)

@gomezdegomera
Copy link

Hi,

I have similar issue and questions in a multithreaded env with a single client.

Moreover I wonder how the two SessionTable in Connection object are used, if, apparently, to retrieve a Session from a Connection, authenticate method is the only public way to do it and it does not reuse open sessions of the Connection.

Thanks

@peppogit
Copy link

peppogit commented Dec 18, 2024

My question is related to the ones above.

How can I share a connection/session between unrelated classes? I cannot change existing "interfaces" (in terms of constructors/setters) but I can do some further implementation building the SMB client and get (if possible) an existing session.

The default solution is establishing a brand new share connection...

Thanks for the great job and thanks for answering

@hierynomus
Copy link
Owner

I'd suggest reading up on design patterns. There's multiple options, depending on what you like:

  1. ThreadLocal instance if they're in the same thread
  2. A global static instance, if you want to share across threads

Each has its benefits and downsides with regard to correct management of connections etc.

@gomezdegomera
Copy link

Hi, I don't understand the approach suggested to resolve the initial request. Establishing a shared connection, does not mean getting existing sessions from it, sessions are not reusable objects of the same connection. This seems to be the problem, and authentication to obtain a new session costs. Session pool management would be a great feature to incapsulate into the client itself. The fact is that someting like that exists into the client as a structure (sessionTable) but it is not clear how to use the public interface of the client properly to reusing sessions of the connection in that table or in general.

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

4 participants