EventStore / EventStore-Client-Go

Go Client for Event Store version 20 and above.
Apache License 2.0
105 stars 27 forks source link

Fixed race condition and overwriting of call credentials. #160

Closed johnbywater closed 11 months ago

johnbywater commented 11 months ago

Fixed: Fix race condition and overwriting when setting call credentials

I adjusted the way "basic auth" call credentials are implemented, so that (1) the client configuration is not updated, (2) the client configuration is fully processed into a map of headers, (3) the connection is not given any call credentials, (4) call credentials are passed into each call as call options, (5) if credentials are provided in the options when a client method is called by user then a new credentials object is constructed and used as one of the gRPC call options, and (6) otherwise if the client been configured with credentials then those are used as one of the gRPC call options.

This means that the "global" credentials are not overwritten by credentials provided when a client method is called, and there isn't a race condition between concurrent client method calls on the overwriting of the "global" credentials.

I need this because I'm working on a project that has CI which fails on race conditions, and it failed on this race condition. Looking at it I also realised the (likely) issue of overwriting "default" client configured call credentials with credentials passed when a user calls a method (what the race condition is all about).

By the way, this is also how the Python client works, by passing in either the method credentials or otherwise the client credentials, for each call. For example here and here and here etc, 25 times.

johnbywater commented 11 months ago

Replacement for #159.

johnbywater commented 11 months ago

By the way your linting job isn't working. Look at the "Code formatting checks".

/home/runner/work/_temp/b5f8d893-83e1-4488-bb8d-4457e330c4a1.sh: line 1: goimports: command not found
johnbywater commented 11 months ago

Thank you @YoEight