Error incomplete while reading stamp frame - #5
Conversation
Intention is to handle properly an unexpected state, that has been experimented: "the socket stream is not at end, but reading the next byte answers nil and raise errorIncomplete".
…mpmedium next line + updated comment
|
I wondering if you saw this PR as I was a bit messy with my previous one ? :) |
|
I did see this issue and it is on my todo list. But I am not yet sure what to do or how to react. I am very hesitant to change code in this area (let's call it socket stream behaviour related to network states). Do you have a reproducible case ? In my opinion, #next is ill specified in Pharo: it returns the next available item, it blocks, but it can both throw an exception as well as return nil - for example, a stream that is #atEnd will return nil for #next, while it there could also be an StreamEnded exception. Your code is also written to assume lots of internal knowledge, which is never a good sign. But of course, the issue must be fixed somehow. |
|
Ok, thanks for answering ! Unfortunately, I don't have a reproducible case. I am myself also not completely satisfied with my changes. I would see the error context as 3 different layers interacting together.
And as you, the lower we are, the less I would question about something wrong, The changes I pushed with this PR are intended to enhance robustness in the second layer, So I understand it is not a straight forward issue that maybe needs time to be thought about. |
|
"At the end, I am still curious to understand why a ConnectionClosed occuring in the first layer would be ignored (as in #fillReadBuffer). As the lowest level, I guess there might be some sensitive concerns." It is not really ignored as far as I can see. Suppose you read 1k bytes while filling the buffer and then ConnectionClosed happens because the server says he's done. Then the higher layers still need the 1b bytes read previouslty, and only then the stream will be atEnd. But yes, maybe the line reader is not 100% OK, there are other line readers in the image (at least 2 in Zn), maybe we need to compare the code. |
|
Ok, then I understand the concern, thank you. Following this logic, maybe the #readLine method from StampMedium should consider it has reach the end when such an errorIncomplete occurs while waiting for the next character. |
|
Have a look at ZnLineReader>>#processNext and ZnFastLineReader>>#nextLine both are taking #atEnd and #next isNil into account, we should try to add that here as well, probably. |
|
OK, what about ? |
|
Yes! Would be consistent with the other methods you pointed out. |
When the connection get closed, we catch the ZnIncomple and let the #readLine method answers what has been read before. This behavior is consistent with other readLine methods ( ZnLineReader>>#processNext and ZnFastLineReader>>#nextLine)
|
I just pushed a new commit that implements this solution. Side issue: this file appear in the changes whereas I did not intentionally make any change from pharo: repository/Stamp.package/TStampFrameWithBody.trait/properties.json Could it be an issue around "pharo git format" and how traits are represented ? |
You were right, I should first do the pull request to the origin repo, which is this one.
Sorry, I am on my way to be used to the contribution process :)
The intention of this PR is to handle properly an unexpected state, that has been experimented:
"the socket stream is not at end, but reading the next byte answers nil and raise errorIncomplete".
Here some more info about the case I think we faced:
"Ok I think I see a bit more precisely what can be the scenario for this "unexpected" state:
When sending "next" to the socket stream, and the buffer is empty, the expected behavior of the "next" method is to wait for data.
As soon as it get some, it answers.
EXCEPT when the connection close:
So if the connection close while "next" method is waiting for data, ConnectionClosed exception will be ignored , and nil will be answered. Then, patatra"