-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
In what version(s) of Spring Integration are you seeing this issue?
spring-integration-sftp 6.0.1
Describe the bug
If SFTP client is not yet initialised and two threads simultaneously try to use SFTP client, one of them may fail.
DefaultSftpSessionFactory::initClientSession
calls DefaultSftpSessionFactory::initClient
which initialises the client.
Client initialisation is done only by the first thread.
The second thread skips initialisation and may use uninitialised/partially initialised client.
It causes exception:
Caused by: java.lang.IllegalStateException: failed to create SFTP Session
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:291)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:67)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:85)
at org.springframework.integration.file.remote.session.CachingSessionFactory$1.createForPool(CachingSessionFactory.java:82)
at org.springframework.integration.util.SimplePool.doGetItem(SimplePool.java:206)
at org.springframework.integration.util.SimplePool.getItem(SimplePool.java:187)
... 20 common frames omitted
Caused by: java.lang.IllegalStateException: SshClient not started. Please call start() method before connecting to a server
at org.apache.sshd.client.SshClient.doConnect(SshClient.java:626)
at org.apache.sshd.client.SshClient.doConnect(SshClient.java:615)
at org.apache.sshd.client.SshClient.connect(SshClient.java:546)
at org.apache.sshd.client.session.ClientSessionCreator.connect(ClientSessionCreator.java:199)
at org.apache.sshd.client.session.ClientSessionCreator.connect(ClientSessionCreator.java:188)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.initClientSession(DefaultSftpSessionFactory.java:314)
at org.springframework.integration.sftp.session.DefaultSftpSessionFactory.getSession(DefaultSftpSessionFactory.java:281)
... 25 common frames omitted
To Reproduce
After application startup when SFTP client is not yet initialised make two SFTP requests simultaneously
Expected behavior
All threads must wait for client initialisation.
Uninitialised/partially initialised client should never be used.