[jcifs] Why logoff after failed SmbComTreeConnectAndX?

Michael B Allen ioplex at gmail.com
Tue Dec 3 18:50:30 MST 2013


On Tue, Dec 3, 2013 at 5:48 PM, Shon Vella <svella at idauto.net> wrote:
> I’ve been chasing a couple of issues for several days now and finally
> tracked both of them down to a couple of lines in the exception handler for
> SmbSession.send():
>
>             if (request instanceof SmbComTreeConnectAndX) {
>                 logoff(true);
>             }
>
> in my case, the SmbComTreeConnectAndX is failing because the share doesn’t
> exist, in which case the logoff() seems extreme. The logoff does a tree
> disconnect on all the trees associated with the session, which in turn
> closes any open files, including named pipes. The initial issue I was trying
> to track down was named pipe that was being used in another thread that was
> randomly getting closed prematurely.
>
> The second issue I was trying to track down was sudden spikes in the number
> of sessions open on the server. I was finally able to duplicate the spikes
> with a little loop like this:
>
>         SmbFile badShare = null;
>         try {
>             badShare = new SmbFile("smb://MYSERVER/BOGUS", new
> NtlmPasswordAuthentication(“MYDOMAIN", "Administrator", “mypassword"));
>             for (int i = 0; i < 1000; i++) {
>                 try {
>                     System.err.println(i);
>                     badShare.exists();
>                 } catch (SmbException e) {
>                 }
>             }
>         } catch (MalformedURLException e) {
>         }
>
> Which will very quickly cause 1000 sessions to be opened on the server and
> will cause many other operations to fail with SMB Error 0xC0000205
> (STATUS_INSUFF_SERVER_RESOURCES)
>
> I’m not sure why doing the logout on failure of SmbComTreeConnectAndX leaks
> connections, but by commenting it out, the session count remains steady at 1
> from the client machine.
>
> So the big question is why/when would a logoff() be the right thing to do?
> What is going to break of I remove it completely? Are there specific error
> codes that would be a good indication that the logoff() is really necessary?

Hi Shon,

I don't think that particular logoff(true) clause is vitally
important. It's very possible that it's trying to compensate for some
kind of permissions error situation which of course is not applicable
if you're explicitly providing credentials (as opposed to using the
NtlmAuthenticator to obtain credentials dynamically). So I think you
could try removing it.

Mike

-- 
Michael B Allen
Java Active Directory Integration
http://www.ioplex.com/


More information about the jCIFS mailing list