GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix #4 - Handle thread safety for shared clients (Celery fixes) by Deadpool2000 · Pull Request #17 · openapi/openapi-python-sdk

Conversation

@Deadpool2000

@Deadpool2000 Deadpool2000 commented Apr 9, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

hey @francescobianco ,

this is fix for #4

I’ve been looking into the issue where OauthClient was blowing up when shared across Celery workers, and it’s basically down to how we were handling the internal httpx client. Since we were initializing it once in the constructor, every single worker thread was trying to squeeze through the same connection pool at the same time. That’s why users were seeing those random failures and corrupted data - the internal state just couldn't handle that much concurrent noise.

To fix this without making everyone rewrite their Celery tasks, I moved the internal client over to a property backed by threading.local(). So now, even if you define the client once at the top of your file, each worker thread will lazily spin up its own private connection the first time it actually needs to make a call. It completely solves the thread-safety headache while keeping the code looking exactly the same from the outside.

One thing I wanted to be careful about was not breaking the custom client injection. I know some people pass in their own sessions for custom retries or proxies, so I made sure that if you explicitly pass a client in the constructor, it still uses that exact object across all threads. This keeps things backward compatible for power users while making the default behavior safe for everyone else.

I also threw in a new test file, tests/test_thread_safety.py, which just fires off a bunch of threads and makes sure they aren't stepping on each other's toes by checking that they each get a unique client instance. All the original tests pass too, since the mocks still hook into the property correctly.

Let me know what you think!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@francescobianco

francescobianco commented Apr 28, 2026

Copy link
Copy Markdown
Member

This looks great — really solid improvement, especially on the thread-safety side 👏

There are just some merge conflicts at the moment. Could you please rebase your branch and update the PR?

Thanks as always! 🙏@Deadpool2000

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Deadpool2000 added 6 commits May 10, 2026 22:25
@Deadpool2000
make OauthClient thread-safe using threading.local
c0aebaa
@Deadpool2000
implement thread-local connection handling for shared instances
e4f5d4f
@Deadpool2000
test: add thread-safety verification suite for sync clients
d6b0211
@Deadpool2000
fixed split loop statement issue
3827806
@Deadpool2000
fix ruff linting issues and sort imports in thread-safety tests
90bf9fc
@Deadpool2000
fix ruff linting issues and sort imports in thread-safety tests
81cd2a8
@Deadpool2000
Deadpool2000 force-pushed the fix-4 branch from 7c7dc37 to 81cd2a8 Compare May 10, 2026 16:57
@Deadpool2000

Deadpool2000 commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

@francescobianco Check it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@francescobianco

francescobianco commented May 12, 2026

Copy link
Copy Markdown
Member

This looks great — really solid improvement, especially on the thread-safety side 👏

Thanks for following the suggestion! The PR will be merged shortly, and we’ll likely release a new version in the next few days.

Thanks again as always! 🙏 @Deadpool2000

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@francescobianco
francescobianco merged commit 21248d6 into openapi:main May 12, 2026
4 checks passed

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@Deadpool2000 @francescobianco
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.