Fixed connectHeaders
concurrent map read & write
#127
Merged
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.
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 theDefaultHeader
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, theconnectHeaders
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.