-
Notifications
You must be signed in to change notification settings - Fork 380
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 file double time sometimes cause copy problem wh #572
Comments
It is a well-known situation that calling Which returns:
Also, note that attempting to closing an Now, all of that said, we could support this a little better, by locking the P.S.: Note that your code was erroneous even if using |
Hello, I knew double close is not a really clean code, I was fool by other module implementation of Close where Close can be called safely multiple time. I create the issue it because the ReadFrom error happend randomly, and it take me some time to identify that was the second close() on a already closed file reference that impacting another file reference copy process, it seems to me very sneaky. With your solution, it will be more explicit and preventive 👍 |
This may not be strictly true. Since you’re throwing away any errors that are happening, you cannot know whether these multiple closes are actually safe or not. Hm, this is still kind of weird though, because the And even with Actually:
This is the sftp server related what the request it got was. Which appears to be:
And that’s just all sorts of wrong. There shouldn’t really be a way that we can even send that. |
I think what might help is more of the server logs preceding one of these errors. 🤔 While the logs are, I’m sure, relatively free of sensitive information, you should probably attach it as a file, rather than embed it. There’s almost certainly a lot of noise going on in there. |
here the log of one run with 2 copy errors :
|
Interesting, found two corresponding
From here, we can then extract the entries for
Wait a second,
Hm. The ones reusing a handle occur immediately after the close for that handle. Something is very sketchy here, and it’s not immediately apparent that it would be our code. |
Congratulations! You have managed to stumble across a race condition in openssh! There is actually absolutely nothing wrong with our code. It’s operating correctly, and openssh is the one which is misbehaving. I’ll be isolating it, preparing an issue report to their repo, then will link to the issue here. (And maybe a PR if I can work out how to address it at the same time.) |
Oh ok, thank you for your analysis on that ! 👍 |
Hm… ordering them by line numbers, I see something different. No bug or race condition in Instead, it’s (obviously) a race condition in the code which is multithreaded: So, this is a bug in |
If you can try out the new PR, and verify that you don’t seem to hit the error anymore. I know we cannot for sure say it doesn’t happen anymore, but some amount of confidence would be great. |
Hello,
version of go :
1.20.5
version of lib sftp :
v1.13.6
version of sftp server:
OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
I sometime experiment a bug when my code close 2 times the same sftp.File ref in concurrent situation
here the code to reproduce :
main.go
go.mod
When i launched this code, sometime i got 1 or 2
SSH_FX_FAILURE
on theReadFrom
method .output of my code :
On server side, I can see that type of logs:
Now, if I replace
with
I cant reproduce the error.
In the Close method documentation, it is mention that
Close closes the File, rendering it unusable for I/O.
.Is-it really the case ?
Does a PR that add a flag check "alreadyClose" in the Close method before send a close request to sftp server is a great idea ?
thank you.
The text was updated successfully, but these errors were encountered: