Skip to content

image-rs: dispatch OpenPGP signature verification to blocking thread pool - #1560

Open
mkulke with Copilot wants to merge 4 commits into
mainfrom
copilot/isolate-synchronous-code-blocks
Open

mkulke with Copilot wants to merge 4 commits into
mainfrom
copilot/isolate-synchronous-code-blocks

Conversation

Copilot AI commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Calling CPU-intensive synchronous code directly on an async executor thread risks starving the event loop. The judge_single_signature function — which parses GPG keyrings, decodes and decompresses OpenPGP packet streams, and runs cryptographic verification — was called inline from the async simple_signing_allows_image.

Changes

  • image/mod.rs — Derive Clone for Image (all fields already Clone)
  • policy/ref_match.rs — Derive Clone for PolicyReqMatchType (string-only enum variants)
  • policy/simple/mod.rs — Wrap each judge_single_signature call in tokio::task::spawn_blocking, cloning the necessary data into the closure:
let result = tokio::task::spawn_blocking(move || {
    judge_single_signature(&image, signed_identity.as_ref(), &pubkey_ring, sig)
})
.await
.context("signature verification task panicked")?;

Follows the existing spawn_blocking pattern already used in pull.rs for decryption key derivation.

The `judge_single_signature` function performs CPU-intensive work:
parsing GPG public keys from a keyring, parsing OpenPGP packets from the
signature blob, and running cryptographic signature verification.  When
called directly from the async `simple_signing_allows_image` function this
work runs on the async executor thread and can starve the event loop.

Dispatch each verification call through `tokio::task::spawn_blocking` so
the blocking work runs on a dedicated thread pool thread.  To make the
captured data `Send + 'static` add `Clone` to `Image` (all fields already
implement `Clone`) and `PolicyReqMatchType` (enum of plain string variants).
Copilot AI changed the title [WIP] Isolate longer synchronous code blocks in async contexts simple: dispatch OpenPGP signature verification to blocking thread pool Jul 15, 2026
Copilot AI requested a review from mkulke July 15, 2026 09:50
@mkulke mkulke changed the title simple: dispatch OpenPGP signature verification to blocking thread pool image-rs: dispatch OpenPGP signature verification to blocking thread pool Jul 15, 2026
@mkulke
mkulke marked this pull request as ready for review July 15, 2026 11:30
@mkulke
mkulke requested a review from a team as a code owner July 15, 2026 11:30

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 moves CPU-intensive OpenPGP signature verification (judge_single_signature) off Tokio async executor threads by dispatching it to tokio::task::spawn_blocking, preventing potential event-loop starvation during image signature policy checks.

Changes:

  • Wrap each judge_single_signature invocation in tokio::task::spawn_blocking within simple_signing_allows_image.
  • Derive Clone for Image so it can be moved into blocking tasks.
  • Derive Clone for PolicyReqMatchType so policy parameters can be moved into blocking tasks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
image-rs/src/signature/policy/simple/mod.rs Offloads OpenPGP signature verification to Tokio’s blocking thread pool.
image-rs/src/signature/policy/ref_match.rs Adds Clone for PolicyReqMatchType to support moving policy data into blocking tasks.
image-rs/src/signature/image/mod.rs Adds Clone for Image to support moving image data into blocking tasks.

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

Comment on lines +93 to +96
for sig in sigs {
let image = image.clone();
let signed_identity = parameters.signed_identity.clone();
let pubkey_ring = pubkey_ring.clone();
Comment thread image-rs/src/signature/policy/simple/mod.rs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Magnus Kulke <mkulke@gmail.com>
Copilot AI requested a review from mkulke July 15, 2026 13:15
@Xynnn007

Copy link
Copy Markdown
Member

@mkulke looks like the dco is wrong. Do you know how to handle this?

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.

Isolate longer synchronous code blocks in async contexts

4 participants