-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
Memory/Thread Leak #74
Comments
Hey, thanks for the issue. Let me answer them in order:
|
After I use #75 , I got an error:
|
@qihuijia Just looking at it on my phone, it does appear that SFTPClient.close() is an async function, and SSHClient.withSFTP() calls it without await. It's also in a defer block, which doesn't support async function calls in Swift. I've got a month of Swift experience, never actually used defer myself, and have not tried the PR yet, so I must be missing something, but I feel like that shouldn't compile. All that said, it's completely unrelated to this issue, you should definitely open a new issue for that. @Joannis Sorry I did not see your response sooner, I will definitely give the PR a go asap. I also forgot to mention that Xcode's memory leak detection was no help here. I will give this a go with password authentication to rule out RSA as the issue. Also a heads up, I may have some PRs coming your way soon as I have noticed a few issues in the library, and a few features that would be nice to have. I don't have much experience with Git and writing PRs so I may need a bit of help when the time comes. |
@qihuijia apologies for that! I had a couple PRs that I think individually worked, but I should've tested once more with all changes together. |
@christianh104 and @qihuijia the close() call was fixed this morning (my time). The defer statements can't be async, but some close() calls exposed by NIO can be synchronous so don't run into this limitation. The issue is that I exposed it as asynchronous API to return potential errors. @christianh104 I waited a bit for feedback, but started getting more and more questions about it. The error is definitely not wanted, so I fixed that in those two PRs which are now merged and usable as of 0.9.1 |
I'm closing this issue since it should be all good now. Please do re-open if something is missing. |
Thanks very much. The fix is very fast. It works for me. Have a nice day |
Describe the bug
When a connection is closed, a thread remains open (NIO-ELT-X-#0, where X increases with each connection). If a connection is opened and closed over and over, the thread count and memory usage just keep increasing, until eventually a DNS error occurs on the 249th connection attempt.
Reproducer Sample
main.swift (must be run outside of sandbox to read private key):
Client:
Server:
Additional context
I've never touched Swift before this week, so I may be doing something wrong, but the repro seems pretty straightforward.
I wondered if the SFTP channel wasn't cleaning up, so I tried adding this to SFTPClient.swift:
public func close () async throws { try await self.channel.close() }
and then uncommenting
try? await sftp.close()
in main.swift. No luck.Side note: If there is a better way to determine the private key type than brute force, I am interested to hear it.
The text was updated successfully, but these errors were encountered: