-
Notifications
You must be signed in to change notification settings - Fork 718
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
Unexpected buffer sharing caused request body concatenated or replaced #917
Comments
@stonelgh Thanks for reaching out. I will analyze the issue with given code snippet and get back. FYI -
This PR was merged long ago, so there is no buffer reuse.
This PR is not related to Resty v2 since it is related to upcoming Resty v3. You can see it via labeling. |
@stonelgh I have successfully reproduced the issue at my end using the code snippet you provided. Buffer reset issue happens with the |
@jeevatkm Commit 67cf80b doesn't actually fix the issue. It simply hides it by avoiding buffer reuse. The root cause to the issue is that the same buffer is put back to the pool each time the request gets retried in the mentioned scenario. As a result, the same buffer may be concurrently used. |
@stonelgh, I would like to ensure that I have not overlooked any important details. During my analysis of the issue, I observed that the buffer reset was not functioning correctly in this scenario. Therefore, I implemented logic to prevent the use of the buffer if it contains unread bytes. Instead, I create a new buffer to avoid potential sharing or concurrent issues. Engaging in open and constructive discussions is beneficial. |
@jeevatkm When it enters
It acquires a buffer from the pool and reads the body into the buffer. It stores the buffer to Once a retry is needed, in the following attempts, it will not enter So the buffer is released back to the pool multiple times in the retry situation. And this is the root cause of the issue. To fix it, we either do not release the buffer back to the pool until the request is done, or we acquire a new buffer from the pool and release it back in each attempt. |
@stonelgh Thanks for the detailed walkthrough. Now I understand what you have meant in the previous message. It seems I overlooked the |
In our usage, we found that files were being transferred to incorrect paths, or two files were being merged and transferred to the same location.
After investigation, we found that this issue can be reproduced in the following scenario, from v2.9.1 to the latest v2.16.0: SetContentLength(true), set a reader stream as the request body and when retry occurs.
This issue can be observed with the following code snippet:
Similar or related:
The text was updated successfully, but these errors were encountered: