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

Fixed connectHeaders concurrent map read & write #127

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Fixed connectHeaders concurrent map read & write #127

merged 1 commit into from
Aug 7, 2024

Conversation

Dharmey747
Copy link
Contributor

In the latest update the possibility to define CONNECT headers was implemented, I encountered a bug with this new feature when setting a proxy to the client instance very quickly, that causes a race condition.

When setting a new proxy, the connectDialer will write the proxy authentication credentials to the DefaultHeader map. This caused no issue in previous versions because a new header map was spawned every time (make(http.Header)) but in this version the same map is used, the connectHeaders one.

Since writing and reading a map concurrently in go isn't supported, when lots of proxy change operations are happening it will eventually panic because two threads will try to write to the same map at the same time.

To fix this, I've implemented the built-in Clone() method to clone the header map, so every instance will have its own header map and nothing else will be trying to read or write to it.

@bogdanfinn
Copy link
Owner

@Dharmey747 thank you.

@bogdanfinn bogdanfinn merged commit 0e2706b into bogdanfinn:master Aug 7, 2024
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