-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Close Sftp Session before exception is thrown ? #3827
Comments
Confirmed. Feel free to contribute the fix: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc. In our tests we use Apache Mina and its Thank you! |
Fixes spring-projects#3827 The `AbstractRemoteFileOutboundGateway.doGet()` for a `STREAM` option does not close the `session` in case of error. This may lead to some leaks or exhausted caches * Close `session` in the `catch()` of the `AbstractRemoteFileOutboundGateway.doGet()` * Adjust the `SftpServerOutboundTests` to configure a `CachingSessionFactory` for the `testStream()` to verify there is no leaks attempting to `GET STREAM` non-existing remote file twice **Cherry-pick to `5.5.x`**
Fixes #3827 The `AbstractRemoteFileOutboundGateway.doGet()` for a `STREAM` option does not close the `session` in case of error. This may lead to some leaks or exhausted caches * Close `session` in the `catch()` of the `AbstractRemoteFileOutboundGateway.doGet()` * Adjust the `SftpServerOutboundTests` to configure a `CachingSessionFactory` for the `testStream()` to verify there is no leaks attempting to `GET STREAM` non-existing remote file twice **Cherry-pick to `5.5.x`**
Fixes #3827 The `AbstractRemoteFileOutboundGateway.doGet()` for a `STREAM` option does not close the `session` in case of error. This may lead to some leaks or exhausted caches * Close `session` in the `catch()` of the `AbstractRemoteFileOutboundGateway.doGet()` * Adjust the `SftpServerOutboundTests` to configure a `CachingSessionFactory` for the `testStream()` to verify there is no leaks attempting to `GET STREAM` non-existing remote file twice **Cherry-pick to `5.5.x`**
Currently using Spring Integration 5.5.9 but the code looks the same on the main branch.
Describe the bug
Our application is creating sftp connections that stay opened and are never released to the connection pool.
After some time the pool is empty and we get an error "Timed out while waiting to acquire a pool entry".
For instance, this a a view of the sftp connection for the last 2 days :
After some digging I found that ths sftp connection is never closed when an exception is thrown at this moment :
https://github.com/spring-projects/spring-integration/blob/main/spring-integration-file/src/main/java/org/springframework/integration/file/remote/gateway/AbstractRemoteFileOutboundGateway.java#L667
To Reproduce
First you need a sftp server.
Then you need a SessionFactory (this is our configuration) :
And a sftp-outbound-gateway with a get command and a -stream option :
When you try to get a file that doens't exist, the session stays opened.
Expected behavior
Close the sftp connection before throwing the ErrorMessage so it doesn't stay opened.
I was thinking something like this (maybe adding a non-null verification or other stuff would be better) :
Sample
https://github.com/corentin-pasquier/sample-issue-sftp-connection
You just need a sftp server in local.
You can run this docker command to get one :
Other information
I didn't check if this phenomenom happens with other commands, but it would be interesting to check.
The text was updated successfully, but these errors were encountered: