Skip to content
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

Race condition due to ResponderFromResponse() copying Body object #93

Closed
ascherkus opened this issue Aug 7, 2020 · 3 comments · Fixed by #94
Closed

Race condition due to ResponderFromResponse() copying Body object #93

ascherkus opened this issue Aug 7, 2020 · 3 comments · Fixed by #94

Comments

@ascherkus
Copy link

I came across this when parallelizing some backend HTTP calls.

The short of it is that NewStringResponder(), NewBytesResponder(), etc... are all subject to racing since ResponderFromResponse() will create new http.Response objects use the same underlying Body object in each response.

My assumption would be that supplying a string in NewStringResponder() would be free of races. If so - I believe a possible fix is to inline ResponderFromResponse() into each method and ensure NewRespBodyFromString() or NewRespBodyFromBytes() is called for each new http.Response object created.

maxatome added a commit to maxatome/httpmock that referenced this issue Aug 8, 2020
Close jarcoal#93

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
maxatome added a commit to maxatome/httpmock that referenced this issue Aug 8, 2020
Closes jarcoal#93

Signed-off-by: Maxime Soulé <btik-git@scoubidou.com>
@maxatome
Copy link
Collaborator

maxatome commented Aug 8, 2020

Thanks for the report @ascherkus
could you check the PR #94 please?

@ascherkus
Copy link
Author

tested locally and works for me!

@maxatome
Copy link
Collaborator

Fine, v1.0.6 released. Thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants