-
Notifications
You must be signed in to change notification settings - Fork 93
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 the file if TransferOpen fails. #70
Conversation
It's actually a bit more complex than that, see #66. For reading, it's not an issue but for writing it means we might have failed to flush the file, which can be a core part of writing when you're using third-party online services. And this library was built with that in mind. |
Sorry I got the impression from the issue comment that this was the route you wanted to take. We use this at my company to provide an FTP interface to S3, I discovered this issue because we had a client that was creating bad active transfer requests. Similar to #66, the existing While its not a standard io interface, if |
Yes sorry, I wasn't clear. This is the direction I wanted to take but I also wanted to push it a bit further, which is to check if anything goes well. You're interested in avoiding file descriptor. And it's equally important to make sure close/flush errors are correctly reported, these two subjects are basically handled at the same time. I might be missing something but I don't think we need the
Whatever happens, if we open the file, we will close it. |
@marshallbrekka Ok to close it and review #71 instead? |
That would solve the immediate issue, but taking it further I was thinking about when a client does not exit gracefully. If the interface was expanded to allow closing with error conditions, then the storage layer can discard partial files (if it so desires). If there is concern about forcing all implementations to support such a mechanism, it could be declared under a 2nd interface. Maybe something like type FileStreamErrorCloser interface {
CloseWithError(error) error
} file, err := c.openFile(c.absPath(c.param), append)
tr, err := c.TransferOpen();
if err != nil {
if closer, ok := file.(FileStreamErrorCloser); ok {
closer.CloseWithError(err)
} else {
file.Close()
}
} |
@fclairamb yeah that PR lgtm, would still like some more discussion around handling of failures on write. Its not terribly critical to us, but would be nice if we can omit writing partial files in cases of failure. |
Oh right. Completely missed the point here. |
Fixes #69