-
-
Notifications
You must be signed in to change notification settings - Fork 947
Consider revising behavior of SftpFileStream #194
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
Comments
As I mentioned offline, I think you're moving a little too fast here by rewriting SftpFileStream from scratch. Rewriting for performance without affecting behavior is of course ok, but you're definitely changing the way SftpFileStream works for a client. From a single(-threaded) consumer point-of-view, the current behavior does not make any sense. From a multi-threaded point-of-view, it makes sense that advancing the position in thread A by reading should not affect the position of thread B that is writing. The original implementation was clearly ment to be thread-safe. Before we rewrite SftpFileStream we should first discuss how we expect it to work (eg. do we want it to be thread-safe), and perhaps even involve our user base. |
Well, the idea behind SftFileStream was to have same behaviour as FileStream, and for that I used Microsoft implementation of it here as a starting point (in the previous implementation I was using Mono as reference I think), and replace native functionality to access files with SSH equivalent functions. I did leave some parts out of it, the one that has to do with async, at least for now we can restore it later. So I guess the question is how SftpFileStream behavior now is different from FileStream and if should it be. As far as I know FileStream is not a thread safe but perhaps we can make it different and restore locking to ensure thread safe as it was before, I just didnt want to restore it just now as it was my first attempt to rewrite it and I was worried about race conditions and locking myself out but I can take a look at it later. I know its still need to be corrected so it will pass tests and compile for .NET Core and perhaps other environments but I guess we can address it later once we finalize behaviour. |
For the next - and long overdue - release, I think we should stick with the previous behaviour. What do you think? |
Well, we can stick to previous behavior then, no problem. I guess my question is how previous behavior is different from current one, and is previous behavior is correct or perhaps it needed to be changed of fixed. |
Personally, I consider the current behavior broken. Since you referenced this issue in your commit, I assume you somehow modified the implementation. |
Well, the reason I called it a complete rewrite is because I used Microsoft code as point of reference instead of Mono one. So it was perhaps confusing, sorry about that. So as far as I know it fixes the issue that you mentioned while keeps Stream behavior same as Microsoft FileStream one so it should be any breaking changes or changes in behavior. |
Not sure if I understood you correctly. Are you saying that there should not be any breaking changes? Again: I don't like the current behavior, but changing it may break existing applications. |
What I mean by no breaking changes is that all methods still the same and have the same signature and same behavior. If you like, sure, we can keep previous version and revert it back so new version could be released, but then the issue that you mentioned will not be fixed. I guess we can let people know in release notes that we have improved SftFileStream that will fix that particular issue and perhaps others and will be designed to work the same as FileStream. |
The goal of this issue was to consider/discuss changing the behavior of SftpFileStream. |
Sure, no problem. |
The revision you committed breaks some test I have locally, but I do not consider it a breaking change. However, I still prefer to stick with the previous version from now. I'd like to discuss some other things: Read BufferAssume you've just opened a file, and invoked Scenario 1The number of bytes we received from the remote server is less than or equal to the length requested by the client. Do we:
Answer: and do we:
Answer: Scenario 2The number of bytes we received from the remote server is greater than than the length requested by the client. Do we:
RemarksFor both scenarios above, the first choice avoids allocation of a read buffer and/or - fully or partly - eliminates copy from read buffer to user-provided buffer. The price you pay for that choice is that moving around and reading again from the same area of the file will cause an exra round trip. If the primary usage of the SftpFileStream is forward-only reading, then the second choice is obviously a little more efficient hereby offering a small performance gain for both scenarios. Note:
Thread SafetyT.B.D. |
I've implemented the following changes:
|
Our SftpFileStream currently performs separate householding for read and write mode.
This means - for example - that if you:
The byte that you wrote in step 3 is actually written at position 0 instead of 2.
The following code fragment exposes this:
The text was updated successfully, but these errors were encountered: