-
Notifications
You must be signed in to change notification settings - Fork 833
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
SFTP connections - do we need to disconnect each time? #1660
Comments
The issue does not list the required fields, nor does it share enough info to investigate. There is a ConnectionProvider interface which allows you to control how a connection is established. You can use that to implement any connection/re-connect logic you may need. |
When the queue worker run it does not kill the established connection. If there's 4 workers then there will be 4 established connection stay active. Depending on the server if they have a set timeout then you next call outside that windows will failed. So if you try to connect to the server to receive some file you might get something like this
So my solution is to call disconnect explicitly everytime. There's a ping() method you can use. The ping will check the connection and re-established if necessary but once the job is done the connection still active. I prefer to use disconnect so I know there's no stale connection floating around taking up resources. |
@ttruong15 there is an interface you can implement for custom connectivity checking logic: src/PhpseclibV2/ConnectivityChecker.php |
@frankdejonge thanks that does work but it doesn't meet my needs. That only check if the connection is active or not and then reconnect again. However that will always leave the connection active. The Laravel queue worker when run via supervisor doesn't get kill so it never get to call the __desctruct() of the SSH2 so it can clean up the connection. I have 4 workers which means there's 4 connections sitting idle wasting resources. I want to be able to connect to the server, do what i need to do and disconnect and clean up the connection. Which means every time I access the server it have to reconnect/login again which I am fine with it. Anyway, I think I solved my issue. thanks for your help., Btw, if someone want to implement the connectivity checker the config need to be this |
@ttruong15 i have the same issue, how did you resolve it for you? Since both connectionProvider in SftpAdapter and connection in SftpConnectionProvider are private there is no way to call disconnect on connection. @frankdejonge can we have methods pulic methods getConnectionProvider() in SftpAdapter and getConnection() in SftpConnectionProvider? This would provide flexibility to handle cases like this one when low-level stuff needs to be done (e.g. closing a connection) |
Hey @hasfoug unfortunately I am back to square one. I though I had it sorted with this |
@ttruong15 just so I understand your case better, and possibly can help find a solution. I assume you do not want to reconnect on every job, but when there are no jobs you want to disconnect? Your own connection provider can expose a disconnect method, and the |
@frankdejonge its a bit different, we need to close connection when job is done writing to the SFTP server, since the connection stays open and server blocks futher connections. Its also described here: #1757 I opened a PR with disconnect method: https://github.com/thephpleague/flysystem/pull/1758/files/2f2362f44b1741bb58bee601905d273e59cb3cd4 |
@ttruong15 @hasfoug Solve this problem simply by doing the following:
|
Question
When we submit several jobs via laravel queue, eventually after about 150 jobs we get "unable to access" - would that be because there are too many connections?
Is there such a thing as closing or disconnecting connections after every job?
Thanks
The text was updated successfully, but these errors were encountered: