Skip to content

fix: ClientProvider locking#138

Merged
temporal-nick merged 3 commits intomainfrom
pglass/fix-many-yamux-stream
Aug 19, 2025
Merged

fix: ClientProvider locking#138
temporal-nick merged 3 commits intomainfrom
pglass/fix-many-yamux-stream

Conversation

@pglass
Copy link
Contributor

@pglass pglass commented Aug 18, 2025

What was changed

Correct lock usage to create only one client of a particular type.

Why?

The current logic is not quite thread-safe. It allows many clients to be created when the proxy server is first (re)started, depending on how many requests come in. This is probably not harmful but results in a bunch of unnecessary clients, as well as a confusing metric that indicates many yamux streams are being used.

Checklist

  1. Closes

  2. How was this tested:

Existing unit tests

  1. Any docs updates needed?

@pglass pglass requested a review from yux0 August 18, 2025 14:25
@pglass pglass requested a review from a team as a code owner August 18, 2025 14:25
// Create admin client
c.adminClientsLock.Lock()
defer c.adminClientsLock.Unlock()
c.adminClientsLock.Lock()
Copy link
Collaborator

@temporal-nick temporal-nick Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this method is super-high-throughput, we can use double-checked initialization here:

if c.adminClient != nil {
    return c.adminClient
}
c.adminClientsLock.Lock()
defer c.adminClientsLock.Unlock()
if c.adminClient != nil {
    return c.AdminClient
}
...

@temporal-nick temporal-nick enabled auto-merge (squash) August 19, 2025 20:04
@temporal-nick temporal-nick merged commit 1fde99b into main Aug 19, 2025
6 checks passed
@temporal-nick temporal-nick deleted the pglass/fix-many-yamux-stream branch August 19, 2025 20:08
hai719 pushed a commit to hai719/s2s-proxy that referenced this pull request Nov 24, 2025
* fix: ClientProvider locking

* Double-checked lock

---------

Co-authored-by: Nick Beaumont <nicholas.beaumont@temporal.io>
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