Skip to content

RemoteFileTemplate needlessly marks session dirty in case of no such file error #8745

Closed
@kdebski85

Description

@kdebski85

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

  1. Configure DefaultSftpSessionFactory to point to some valid SFTP
  2. Wrap the factory with CachingSessionFactory
  3. Configure SftpRemoteFileTemplate to use created CachingSessionFactory
  4. Use SftpRemoteFileTemplate::list method with some path that does not exist on the server

Expected behavior

  1. SftpRemoteFileTemplate::list throws exception (the current behaviour)
  2. 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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions