Repository navigation
Reuse one httpx client in phabricator-client and close it in every caller - #7823
Open
WadekarPrashant wants to merge 3 commits into
Open
WadekarPrashant wants to merge 3 commits into
WadekarPrashant wants to merge 3 commits into
Conversation
PhabricatorClient.conduit_call opened a new httpx.AsyncClient for every Conduit call. The client now holds one AsyncClient, with the timeout and the optional Mozilla-Edge-Key header set once, and can be closed with close() or by using it as an async context manager, as BugzillaClient does. Tests that stub httpx.AsyncClient now accept its constructor arguments.
The brokers close their Phabricator client in the app lifespan, next to the Bugzilla client they already close there. The uplift-resolve agent and checkout_revision use their client with async with, for just the calls that need it.
The webhook authorizer keeps the client it is first built with for the life of the app, so the webhook client is now created in the app lifespan and closed at shutdown, like the hackbot client, instead of once per request. The Phabricator action handlers no longer share an lru_cache singleton that was never closed: each action opens its own client with async with and passes it to the helpers. The repository PHID lookup, which alru_cache used to keep, is now kept by repository name so it still runs once per process.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #7821
Same change as #7822 for
testrail-client, followingbugzilla-client:PhabricatorClient.conduit_callopened a newhttpx.AsyncClienton every Conduit call.libs/phabricator-clienthttpx.AsyncClientcreated in__init__, with the timeout and the optionalMozilla-Edge-Keyheader set once.close(),__aenter__and__aexit__, matchingBugzillaClient.{url}/api/{method}), so requests are unchanged.async withandclose()close it, and the edge key header is sent only when configured. Thehttpx.AsyncClientstubs inphabricator-proxyandhackbot-runtimetests now accept the constructor arguments.Where a client is built, and who closes it
agents/{bug-fix,uplift-resolve,autowebcompat-intervention}brokersuplift_resolve/agent.pyasync witharound fetching the source diffshackbot_runtime/revision.pycheckout_revisionasync witharound resolving the stackhackbot-apiwebhooksHackbotClient; the dependency reads it fromrequest.statehackbot-apiPhabricator action handlersasync with, passed to the helpersCallers that only receive a client (
agent_tools.phabricator,phabricator_proxy,uplift_resolve/models.py,phabricator_authorization.py,phabricator_webhook.py) are unchanged.Notes on hackbot-api:
get_phabricator_authorizerkeeps the client it is first built with inapp.state, so it has to live as long as the app.lru_cachesingleton that was never closed. Each action now opens its own client, matching the TestRail handler in Reuse one httpx client in testrail-client and close it in the TestRail handler #7822. The repository PHID lookup, whichalru_cacheused to keep, is now kept per repository name, so it still runs once per process. A test covers it.phabricator_handler.py's diff is mostly re-indentation; "Hide whitespace" shows the real change.Testing
libs/phabricator-client: 49 passedlibs/phabricator-proxy: 10 passedlibs/hackbot-runtime: alltest_revision.pytests passagents/bug-fix: 12 passed, 4 skippedservices/hackbot-api: 581 passed