Skip to content

Proposal: make client safe for concurrent calls when using custom decode config #4084

Description

@noamcattan

I am currently running into a race condition when making concurrent calls to client.Post, when the client has a custom decode configuration.
The race happen here:

dc.Result = into

Since customDc is not nil, the Result field is being written multiple times.

One way to deal with this would be to allow something like a "decoder factory" - a function to create a new decode config on every call instead of using the same one.
The other solution is to clone the custom decoder before writing the result.
(Another solution for me would be to use separate clients, i.e. fixing it on my side, but I think it can be nice to handle it in the library)
I'd be happy to help with the implementation if needed.
Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions