You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Burchi (Jira)" <ji...@apache.org> on 2021/04/28 15:52:00 UTC
[jira] [Updated] (FTPSERVER-501) java.net.SocketException: Socket
closed
[ https://issues.apache.org/jira/browse/FTPSERVER-501?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Burchi updated FTPSERVER-501:
-----------------------------
Description:
Using apache FtpServer to create an internal FTP server in Java, i received some errors. So, i am running a file upload on FTP from 4-5 threads in parallel and from time to time the upload is failing. The behaviour is not always the same, i mean out of 10 successive runs 8 times it works properly.
The error stack trace is:
java.net.SocketException:
{code:java}
Socket closed
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:403)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:609)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:209){code}
The source code generating the error above:
{code:java}
public ReturnStatus sendFile(String remoteFilename, InputStream input, String hostname, String username, String password, Integer port) {
ReturnStatus ftpCreatedStatus = createAndConnectFtp(hostname, port);
if (ftpCreatedStatus != ReturnStatus.Successful) {
return ftpCreatedStatus;
}
try {
LoggingUtils.error(this, "Trying to login to " + hostname);
if (!ftp.login(username, password)) {
return ReturnStatus.FailedLogin;
}
logger.info("Remote server address is " + hostname);
logger.info("Remote system is " + ftp.getSystemType());
ftp.setFileType(FTP.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are behind fire walls these days
ftp.enterLocalPassiveMode();
if (!ftp.storeFile(remoteFilename, input)) {
throw new RuntimeException(ftp.getReplyString());
}
ftp.logout();
} catch (FTPConnectionClosedException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.ServerClosedConnection.setErrorDesc(e.getMessage());
return ReturnStatus.ServerClosedConnection;
} catch (FileNotFoundException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.FileNotFound.setErrorDesc("File Not Found");
return ReturnStatus.FileNotFound;
} catch (IOException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.UnknownError.setErrorDesc(e.getMessage());
return ReturnStatus.UnknownError;
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
// do nothing
}
}
}
return ReturnStatus.Successful;
}{code}
So, it seems that when i am trying to login, the connection is closed even if i I opened the connection before. The line generating the error is:
{code:java}
if (!ftp.login(username, password)){code}
Worth to mention: if I run sequentially everything goes normally
was:
Using apache FtpServer to create an internal FTP server in Java, i received some errors. So, i am running a file upload on FTP from 4-5 threads in parallel and from time to time the upload is failing. The behaviour is not always the same, i mean out of 10 successive runs 8 times it works properly.
The error stack trace is:
java.net.SocketException:
{code:java}
Socket closed
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:403)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:609)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
at org.apache.commons.net.SocketClient.connect(SocketClient.java:209){code}
The source code generating the error above:
{code:java}
public ReturnStatus sendFile(String remoteFilename, InputStream input, String hostname, String username, String password, Integer port) {
ReturnStatus ftpCreatedStatus = createAndConnectFtp(hostname, port);
if (ftpCreatedStatus != ReturnStatus.Successful) {
return ftpCreatedStatus;
}
try {
LoggingUtils.error(this, "Trying to login to " + hostname);
if (!ftp.login(username, password)) {
return ReturnStatus.FailedLogin;
}
logger.info("Remote server address is " + hostname);
logger.info("Remote system is " + ftp.getSystemType());
ftp.setFileType(FTP.BINARY_FILE_TYPE);
// Use passive mode as default because most of us are behind fire walls these days
ftp.enterLocalPassiveMode();
if (!ftp.storeFile(remoteFilename, input)) {
throw new RuntimeException(ftp.getReplyString());
}
ftp.logout();
} catch (FTPConnectionClosedException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.ServerClosedConnection.setErrorDesc(e.getMessage());
return ReturnStatus.ServerClosedConnection;
} catch (FileNotFoundException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.FileNotFound.setErrorDesc("File Not Found");
return ReturnStatus.FileNotFound;
} catch (IOException e) {
logger.log(Level.WARNING, e.getMessage(), e);
ReturnStatus.UnknownError.setErrorDesc(e.getMessage());
return ReturnStatus.UnknownError;
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
// do nothing
}
}
}
return ReturnStatus.Successful;
}{code}
So, it seems that when i am trying to login, the connection is closed even if i I opened the connection before. The line generating the error is:
{code:java}
if (!ftp.login(username, password)){code}
Worth to mention: running sequentially do not encounter any problems
> java.net.SocketException: Socket closed
> ---------------------------------------
>
> Key: FTPSERVER-501
> URL: https://issues.apache.org/jira/browse/FTPSERVER-501
> Project: FtpServer
> Issue Type: Bug
> Reporter: Burchi
> Priority: Major
>
> Using apache FtpServer to create an internal FTP server in Java, i received some errors. So, i am running a file upload on FTP from 4-5 threads in parallel and from time to time the upload is failing. The behaviour is not always the same, i mean out of 10 successive runs 8 times it works properly.
> The error stack trace is:
> java.net.SocketException:
> {code:java}
> Socket closed
> at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:403)
> at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242)
> at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224)
> at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
> at java.net.Socket.connect(Socket.java:609)
> at org.apache.commons.net.SocketClient.connect(SocketClient.java:188)
> at org.apache.commons.net.SocketClient.connect(SocketClient.java:209){code}
>
> The source code generating the error above:
> {code:java}
> public ReturnStatus sendFile(String remoteFilename, InputStream input, String hostname, String username, String password, Integer port) {
> ReturnStatus ftpCreatedStatus = createAndConnectFtp(hostname, port);
> if (ftpCreatedStatus != ReturnStatus.Successful) {
> return ftpCreatedStatus;
> }
> try {
> LoggingUtils.error(this, "Trying to login to " + hostname);
> if (!ftp.login(username, password)) {
> return ReturnStatus.FailedLogin;
> }
> logger.info("Remote server address is " + hostname);
> logger.info("Remote system is " + ftp.getSystemType());
> ftp.setFileType(FTP.BINARY_FILE_TYPE);
> // Use passive mode as default because most of us are behind fire walls these days
> ftp.enterLocalPassiveMode();
> if (!ftp.storeFile(remoteFilename, input)) {
> throw new RuntimeException(ftp.getReplyString());
> }
> ftp.logout();
> } catch (FTPConnectionClosedException e) {
> logger.log(Level.WARNING, e.getMessage(), e);
> ReturnStatus.ServerClosedConnection.setErrorDesc(e.getMessage());
> return ReturnStatus.ServerClosedConnection;
> } catch (FileNotFoundException e) {
> logger.log(Level.WARNING, e.getMessage(), e);
> ReturnStatus.FileNotFound.setErrorDesc("File Not Found");
> return ReturnStatus.FileNotFound;
> } catch (IOException e) {
> logger.log(Level.WARNING, e.getMessage(), e);
> ReturnStatus.UnknownError.setErrorDesc(e.getMessage());
> return ReturnStatus.UnknownError;
> } finally {
> if (ftp.isConnected()) {
> try {
> ftp.disconnect();
> } catch (IOException ioe) {
> // do nothing
> }
> }
> }
> return ReturnStatus.Successful;
> }{code}
>
> So, it seems that when i am trying to login, the connection is closed even if i I opened the connection before. The line generating the error is:
> {code:java}
> if (!ftp.login(username, password)){code}
>
> Worth to mention: if I run sequentially everything goes normally
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org