Revert Pull 1233 fix: The client write operation did not immediately return upon encountering an RST packet. #1849
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The current client implementation does not immediately return when encountering an RST packet while sending a request, but instead ignores it. This behavior is inconsistent with the net/http package and does not make logical sense.
In issue #1232 and the corresponding fix in pull request #1233, an example was used to demonstrate that
net/http
ignores an RST packet when sending a request and continues to read the response. This was cited as a reason why thefasthttp
client should behave similarly.However, that example represents a special case where the RST packet, even if sent, may not be observed by the client. For the
net/http
client, even if the RST packet is observed, it won't respond to it if the response channel in theselect
statement wins over the error channel. But if the error channel for the write request wins priority in theselect
statement, the client will immediately return the error and not continue processing the response.Next, let's modify that example to give the client a chance to observe the RST packet. The principle here is to send the request in segments. This way, the later segments will encounter the RST packet error caused by the earlier segments.
Because the net/http client implementation handles both the reception of the response and the reception of the request's sending result within a single select statement, this revised test does not guarantee a 100% success rate.
Refer to the corresponding source code in the net/http package.
https://github.com/golang/go/blob/36b45bca66d86020f0b4daf1f15b02921a8dad43/src/net/http/transport.go#L2752-L2804
Since the fasthttp client handles requests and responses sequentially, it can definitely observe errors related to RST packets when sending segmented requests. Therefore, I added the corresponding test in this pull request. However, due to the randomness in the net/http package, I did not include a reference test in the submission.