javasmbmicrosoft-distributed-file-systemsmbj

SMBJ throwing transport/eof exceptions


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;

}

Solution

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