Description
In what version(s) of Spring Integration are you seeing this issue?
6.1.3
Describe the bug
The issue applies to all classes which extend org.springframework.integration.file.remote.RemoteFileTemplate
. The description below uses SftpRemoteFileTemplate
from spring-integration-sftp
as an example.
RemoteFileTemplate::execute
method marks session dirty in case of any exception.
It prevents session to be reused and makes CachingSessionFactory
inefficient.
As a result, too many sessions are created and SFTP server may reject new connections.
Certain exceptions, like SftpConstants.SSH_FX_NO_SUCH_FILE
, should not cause session to be marked dirty.
To Reproduce
- Configure
DefaultSftpSessionFactory
to point to some valid SFTP - Wrap the factory with
CachingSessionFactory
- Configure
SftpRemoteFileTemplate
to use createdCachingSessionFactory
- Use
SftpRemoteFileTemplate::list
method with some path that does not exist on the server
Expected behavior
- SftpRemoteFileTemplate::list throws exception (the current behaviour)
- Session is not marked dirty and can be reused by further calls (currently it is marked dirty and cannot be reused)
Probably each class that extends RemoteFileTemplate
should be able to define strategy for differentiating if an exception should mark session dirty.
Workaround
Use SftpRemoteFileTemplate::exists
before each SftpRemoteFileTemplate::list
(call list
only when exists
returns true
)