Skip to content

api-server-rest: retry requests on LocalClosed#1563

Open
kimullaa wants to merge 1 commit into
confidential-containers:mainfrom
kimullaa:reconnect-when-failed
Open

api-server-rest: retry requests on LocalClosed#1563
kimullaa wants to merge 1 commit into
confidential-containers:mainfrom
kimullaa:reconnect-when-failed

Conversation

@kimullaa

Copy link
Copy Markdown
Contributor

The current implementation establishes a connection during process startup and reuses it for all subsequent requests. As a result, if the Attestation Agent is restarted, requests can fail with the error ttrpc err: local stream closed.

When a LocalClosed error is returned, clear the cached client, reconnect to the Attestation Agent, and retry the request once.

The current implementation establishes a connection during process
startup and reuses it for all subsequent requests. As a result, if the
Attestation Agent is restarted, requests can fail with the error
`ttrpc err: local stream closed`.

When a `LocalClosed` error is returned, clear the cached client,
reconnect to the Attestation Agent, and retry the request once.

Signed-off-by: Shunsuke Kimura <pbrehpuum@gmail.com>
@kimullaa
kimullaa requested a review from a team as a code owner July 17, 2026 06:57

@Xynnn007 Xynnn007 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it makes sense, especially we will use systemd to control guest-components to launch in CoCo. Note that this commit will bring in a change that original ASR establishes connection to AA when launched, but new behavior is that the connection will be postponed to the first request.

Also, can you help to implement the CDH side also?

Another point off the topic of the PR, this raise some potential need for integration tests for guest components. We need to care about this @fitzthum


pub struct AAClient {
client: AttestationAgentServiceClient,
client: Mutex<Option<AttestationAgentServiceClient>>,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we use RwLock here? As the call functions (like get_token) are all &self than &mut self. The calls will only do "read" upon the lock and updation will do "write".

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves the resiliency of api-server-rest’s Attestation Agent (AA) ttrpc client by handling the case where the AA process restarts and existing connections become invalid. It introduces a reconnect-and-retry-once behavior when requests fail with ttrpc::Error::LocalClosed, preventing transient failures caused by reused stale connections.

Changes:

  • Replace the single, eagerly-created AA ttrpc client with a cached, lazily re-creatable client stored as Mutex<Option<...>>.
  • Add a call_with_retry helper that retries exactly once after clearing the cached client and reconnecting when LocalClosed occurs.
  • Route AA RPC methods (get_token, get_evidence, get_additional_evidence, extend_runtime_measurement, get_tee_type, get_additional_tees) through the retry helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants