Skip to content

Conversation

@DavyJohnes
Copy link
Contributor

Some libraries which use http client call resp.Body.Close() multiple times from different goroutines, which leads to data race in tests because Close performa some mutations under the hood.
I understand this is mistake in those libraries, but real implementation in net/http doesn't produce data race is same condition. So I believe httmock should not as well.

@maxatome
Copy link
Collaborator

Hello, thanks for your contribution!
As you handle concurrent Close calls, couldn't we also protect Len and Read calls the same way? If the rationale is that users can do bad things, it makes sense, what do you think?
Just a detail, but could you move the mu field before body, as the mutex protects it, IMHO it is clearer.

@DavyJohnes
Copy link
Contributor Author

Hello, thanks for your contribution! As you handle concurrent Close calls, couldn't we also protect Len and Read calls the same way? If the rationale is that users can do bad things, it makes sense, what do you think? Just a detail, but could you move the mu field before body, as the mutex protects it, IMHO it is clearer.

Sure! Done.

@maxatome maxatome merged commit 314d58a into jarcoal:v1 Aug 18, 2025
12 checks passed
@maxatome
Copy link
Collaborator

Thanks!

@DavyJohnes
Copy link
Contributor Author

@maxatome any ETA of next release with this fix?

@maxatome
Copy link
Collaborator

Done v1.4.1 just published.

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 this pull request may close these issues.

2 participants