0

I am utilizing SMBJ to read sbm files, and while everything works, it is throwing,

com.hierynomus.protocol.transport.TransportException: java.io.EOFException: EOF while reading packet

Which I don't understand why, it appears to be closing everything properly. I use the below code with try with resource:

  try (File f = Smb.open(filename)) {
   do my work with the file
  }

And I call the releaseShare method when I am done processing files, and I see a whole lot of logging off sessions, and logging off nested session messages in the logs.. yet, it doesn't seem to matter, it still seems like the libraries think the session/share is still open and when it pings it 10 or 15 minutes later, throws the exception... this doesn't seem to hurt anything, in terms of the program working, but I would like to get rid of the errors... what am I not closing/handling properly?

public static DiskShare getShare() throws Exception
{

    if(share == null){
        SmbConfig cfg = SmbConfig.builder().withDfsEnabled(true).build();
        SMBClient client = new SMBClient(cfg);
        Log.info("CREATE SHARE");
        connection = client.connect(sambaIP);
        session = connection.authenticate(new AuthenticationContext(sambaUsername, sambaPass.toCharArray(), sambaDomain));
        share = (DiskShare) session.connectShare(sambaSharedName);


    }
    return(share);

}

public static File open(String filename) throws Exception{
    getShare();
    Set<SMB2ShareAccess> s = new HashSet<>();
    s.add(SMB2ShareAccess.ALL.iterator().next());
    filename = filename.replace("//path base to ignore/","");
    return(share.openFile(filename, EnumSet.of(AccessMask.GENERIC_READ), null, s,  SMB2CreateDisposition.FILE_OPEN, null));
}

public static void releaseShare() throws Exception{

    share.close();
    session.close();
    connection.close();
    share = null;
    session = null;
    connection = null;

}
Speckpgh
  • 3,332
  • 1
  • 28
  • 46

1 Answers1

1

SmbClient itself is also Closeable. Don't forget to close that to ensure no resources are left open.

Hiery Nomus
  • 17,429
  • 2
  • 41
  • 37
  • There is no ability to call .close() or anything else similar on the client... Its not exposed.. so how should the client be closed? – Speckpgh Aug 14 '18 at 16:07
  • Are you using 0.8.0? We introduced the `close()` method on the SMBClient in that version to prevent leaking resources. – Hiery Nomus Aug 15 '18 at 07:07
  • I thought I was using 0.8.0 I had it in my POM, but apparently hadn't refreshed and was still using 0.7... refreshed and now see the close() method.. thank you. – Speckpgh Aug 15 '18 at 13:59