hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

SmbFiles.copy triggers TransportException (SocketException) #547

Open wmunyan opened 4 years ago

wmunyan commented 4 years ago

Hello, I am using v0.8.0 of your library and am running into an issue. Authentication seems to execute successfully, the SMB share creation indicates success as well. However, I am using the SmbFiles.copy method to move a file from my local machine to the SMB share and receive the following stack trace:

13/04/2020 12:02:21.038 DEBUG com.hierynomus.smbj.share.SMB2Writer - Writing to Windows\temp\ccpa-temp-20200413T120219975\scripts.zip from offset 0
13/04/2020 12:02:21.038 DEBUG com.hierynomus.smbj.connection.Connection - Granted 16 (out of 516) credits to SMB2_WRITE with message id << 8 >>
13/04/2020 12:02:21.038 TRACE com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport - Acquiring write lock to send packet << SMB2_WRITE with message id << 8 >> >>
13/04/2020 12:02:21.038 DEBUG com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport - Writing packet SMB2_WRITE with message id << 8 >>
13/04/2020 12:02:21.062 DEBUG com.hierynomus.smbj.connection.Connection - Granted 1 (out of 500) credits to SMB2_CLOSE with message id << 24 >>
13/04/2020 12:02:21.062 TRACE com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport - Acquiring write lock to send packet << SMB2_CLOSE with message id << 24 >> >>
13/04/2020 12:02:21.062 DEBUG com.hierynomus.smbj.transport.tcp.direct.DirectTcpTransport - Writing packet SMB2_CLOSE with message id << 24 >>
13/04/2020 12:02:21.063 INFO com.hierynomus.smbj.transport.PacketReader - PacketReader error, got exception.
com.hierynomus.protocol.transport.TransportException: java.net.SocketException: Connection reset
    at com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader.doRead(DirectTcpPacketReader.java:53)
    at com.hierynomus.smbj.transport.PacketReader.readPacket(PacketReader.java:69)
    at com.hierynomus.smbj.transport.PacketReader.run(PacketReader.java:47)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader.readFully(DirectTcpPacketReader.java:70)
    at com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader.readTcpHeader(DirectTcpPacketReader.java:59)
    at com.hierynomus.smbj.transport.tcp.direct.DirectTcpPacketReader.doRead(DirectTcpPacketReader.java:48)
    ... 3 common frames omitted

As far as I can tell, permissions are correct on the share and I am authenticating as a member of the Administrators group.

The negotiated connection info looks like this:

DEBUG com.hierynomus.smbj.connection.Connection - Negotiated the following connection settings: ConnectionInfo{
  serverGuid=911fef6d-a7ed-47ab-9817-1bc4570534b7,
  serverName='my.server.myorg.net',
  negotiatedProtocol=NegotiatedProtocol{dialect=SMB_2_1, maxTransactSize=8388608, maxReadSize=8388608, maxWriteSize=8388608},
  clientGuid=9ef9f514-8014-4bc1-9e39-4284ba34d109,
  clientCapabilities=[SMB2_GLOBAL_CAP_DFS],
  serverCapabilities=[SMB2_GLOBAL_CAP_DFS, SMB2_GLOBAL_CAP_LEASING, SMB2_GLOBAL_CAP_LARGE_MTU],
  clientSecurityMode=0,
  serverSecurityMode=3,
  server='null'
}

Any ideas on causes of this issue? I've tried other folders on the same box to no avail. The machine is a domain controller, if that makes a difference. Thanks for any help!

hierynomus commented 4 years ago

Judging from the logs, the file did indeed transfer successfully, can you confirm?

The exception happens in the packetreader, after an SMB_CLOSE was sent. Somehow the connection is immediately dropped on the remote side is what my guess is. Can you look at the server logs to see whether anything can be learned from those?

wmunyan commented 4 years ago

The file doesn't transfer successfully and the application exits. There should be a subsequent application log message indicating the file was copied and the number of bytes. The SMB connection isn't supposed to be closing after this one file is transferred, either - there are another 4 or 5 files to be copied onto the share.

Where can I look in server logs to find further information? Event viewer? The system being connected to is a Windows Server 2019.

Thanks again!

UPDATE: I'm trying to work with folks to check server logs and get back to me. Hopefully there will be more to follow to detail the issues.

hierynomus commented 4 years ago

Great, let me know whether you've learned anything from there.

It fails when it sends the SMB2_CLOSE Message which closes the filehandle and finishes the transfer.