-
-
Notifications
You must be signed in to change notification settings - Fork 29
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
Throw new exception carrying $chunk when fwrite returns 0 #52
Conversation
I think this can be tested with a custom stream wrapper - I'll have to check. But the change itself is fine - thanks :-) |
Nope I tried that trick, that's how I discovered this amphp/amp#265 edit: btw thanks for merge (。◕‿◕。) |
I'm sorry, but I've reverted the commit. The reported information is incorrect in case write-splitting is used, see byte-stream/lib/ResourceOutputStream.php Lines 208 to 215 in 2120bdd
Additionally, I still think giving out that information is misleading for the intended use case, because written bytes mostly don't let you know what the other side received. Those cases where that is the case, are not intended to use |
I don't see how is information incorrect in case write splitting is used. It reports what part of chunk wasn't successful to be written. It doesn't matter that original chunk was splitted, it still returns correct information what data failed to be written |
@ostrolucky It will only return a part of the original chunk, not data based on the complete chunk. |
Yes, that's what I need. I need data that failed to be written, which might be just part of original chunk. I already have original chunk when passing it to I don't understand second part of your sentence though. Splitting is by definition based on complete chunk. |
Maybe $chunk confused you? It could use better naming. It's not original chunk, but last $data passed to fwrite |
@ostrolucky When the chunk is split, the implementation was only returning one portion of the entire split chunk. Also any other chunks in the queue were not included. All remaining chunks in the write queue should be concatenated together if you want the entirety of what was not written. As I said in the linked issue, I don't think this information is useful. It's misleading at best and potentially dangerous. A chunk reported as written is not at all guaranteed to have been received at the other end. I can set up a stream between two machines on my local network, unplug the receiver, and at least a few more chunks never received are reported as written. Additionally, attaching a raw byte-stream to an error can have security implications. I don't exactly know what your use-case is, but I'm going to guess it's serving files over HTTP. Look into byte-range requests. The client should be telling you what bytes they need rather than guessing. |
But chunk reported as unwritten is guaranteed to have not been received at the other end. This is what is this about. I don't care if client recieved all data, I care if all was sent. I can't do anything about data it cannot receive. Ok I will see what can be done about extra chunk splitting. |
How is that information useful though? |
This is prerequisite to do failure recovery. I want to write data failed to be written in one stream into another stream. What I must NOT have is overlapping data in one or other stream. |
@ostrolucky Which data format are you using? Most data formats aren't happy with arbitrary missing chunks in the middle. |
Binary |
This was introduced to be able to handle out of disk size errors. In such case, buffering stops and STDIN is consumed by Responder directly. Originally I wanted this mechanism to be triggered by write failure, but upstream is making this effort harder - see: amphp/byte-stream#52 amphp/byte-stream#54
This was introduced to be able to handle out of disk size errors. In such case, buffering stops and STDIN is consumed by Responder directly. Originally I wanted this mechanism to be triggered by write failure, but upstream is making this effort harder - see: amphp/byte-stream#52 amphp/byte-stream#54
This was introduced to be able to handle out of disk size errors. In such case, buffering stops and STDIN is consumed by Responder directly. Originally I wanted this mechanism to be triggered by write failure, but upstream is making this effort harder - see: amphp/byte-stream#52 amphp/byte-stream#54
This was introduced to be able to handle out of disk size errors. In such case, buffering stops and STDIN is consumed by Responder directly. Originally I wanted this mechanism to be triggered by write failure, but upstream is making this effort harder - see: amphp/byte-stream#52 amphp/byte-stream#54
Fixes #51
I tried hard to write a test for simulating such write failure, but any trick I tried, stream_select will not work with those. Another option would be to use unqualified fwrite call, but I don't think that would be approved.