Skip to content

Add test: FetchOhttpKeys in non-Tokio context#1351

Closed
ValeraFinebits wants to merge 3 commits intopayjoin:masterfrom
ValeraFinebits:test/FetchOhttpKeys
Closed

Add test: FetchOhttpKeys in non-Tokio context#1351
ValeraFinebits wants to merge 3 commits intopayjoin:masterfrom
ValeraFinebits:test/FetchOhttpKeys

Conversation

@ValeraFinebits
Copy link
Contributor

PayjoinMethods.FetchOhttpKeys() panics with "there is no reactor running" when called from a plain .NET async context, because UniFFI polls the Rust future on a .NET thread-pool thread that has no Tokio runtime, and reqwest requires one.

Pull Request Checklist

Please confirm the following before requesting review:

@coveralls
Copy link
Collaborator

coveralls commented Feb 22, 2026

Pull Request Test Coverage Report for Build 22277851434

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 82.484%

Totals Coverage Status
Change from base Build 22262995534: 0.0%
Covered Lines: 10624
Relevant Lines: 12880

💛 - Coveralls

FetchOhttpKeys is exported as a UniFFI async function and is polled
from plain .NET async threads in the C# binding. Those threads do not
carry a Tokio runtime, so reqwest panics with "there is no reactor
running" when the future is polled.

Enable UniFFI's tokio feature and mark fetch_ohttp_keys with
#[uniffi::export(async_runtime = "tokio")] so UniFFI polls it inside
a Tokio-compatible runtime context.

This fixes the runtime panic path and allows errors to be surfaced as
regular IO failures instead of a PanicException.
@DanGould
Copy link
Contributor

I think exposing something like this for convenience is fine but really what you want to do is re-implement the fetch with a native HTTP client. Then use that impl in the integration test and ship it.

Kind of silly to compile reqwest in for this one function. This is true for all of the foreign language implementations.

After enabling Tokio runtime polling for UniFFI async IO, the C#
non-Tokio regression moved past PanicException and began failing with an
IoException against local HTTPS test services.

That failure was a TLS trust issue: TestServices uses a generated
self-signed certificate, while FetchOhttpKeys uses default trust.
The regression should validate async runtime behavior, not certificate
store configuration.

Switch the regression to FetchOhttpKeysWithCert and pass TestServices
certificate bytes. Also export fetch_ohttp_keys_with_cert with Tokio
runtime polling and include _manual-tls in default C# binding
generation features so local and CI builds stay consistent.
@chavic
Copy link
Collaborator

chavic commented Feb 22, 2026

I reproduced the failure and confirmed two separate issues in sequence:

  1. Original panic:
    there is no reactor running from PayjoinMethods.FetchOhttpKeys(...)
    when polled from plain .NET async context (no Tokio runtime on polling thread).

  2. After Tokio runtime fix:
    the panic is gone, but the test hits IoException because local test
    services use self-signed HTTPS certs and the raw FetchOhttpKeys path
    uses default trust.

Follow-up fix:

  • Use cert-aware raw binding in the regression test:
    FetchOhttpKeysWithCert(ohttpRelay, directory, cert).
  • Export fetch_ohttp_keys_with_cert with
    #[uniffi::export(async_runtime = "tokio")].
  • Include _manual-tls in C# binding generation defaults so this path is
    available in local/CI generation.

Result locally:

  • Regression test passes.
  • Full C# tests pass (15 passed, 1 skipped).

@DanGould
Copy link
Contributor

If this unblocks you it's totally ok to move it forward but even medium term (and with llms making this imo fully define problem easy to do now) I suggest superseding it soon

@ValeraFinebits
Copy link
Contributor Author

If this unblocks you it's totally ok to move it forward but even medium term (and with llms making this imo fully define problem easy to do now) I suggest superseding it soon

@DanGould Thanks for the context. Do you expect fetch_ohttp_keys / fetch_ohttp_keys_with_cert to remain part of the public UniFFI API, or are you planning to deprecate/remove them?

@spacebear21
Copy link
Collaborator

At this point it may be best to remove them from the UniFFI API and ensure they are implemented + tested natively in all downstream languages

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.

5 participants