Skip to content

feat(rs-dapi-client): make health check cross-platform (native + WASM)#3371

Merged
lklimek merged 3 commits intofeat/sdk-health-checkfrom
feat/sdk-health-check-wasm
Mar 17, 2026
Merged

feat(rs-dapi-client): make health check cross-platform (native + WASM)#3371
lklimek merged 3 commits intofeat/sdk-health-checkfrom
feat/sdk-health-check-wasm

Conversation

@lklimek
Copy link
Copy Markdown
Contributor

@lklimek lklimek commented Mar 17, 2026

Issue being fixed or feature implemented

Makes the background health check from #3353 compile and run on both native (tokio) and WASM (browser) targets, enabling health checks in the JS/WASM SDK.

What was done?

rs-dapi-client/src/health_check.rs:

  • Two-layer design: run_health_check() (public, takes CancellationToken) delegates to health_check_loop() (runtime-agnostic, takes impl Future<Output=()>)
  • Replaced tokio::select! with futures::select_biased! + FusedFuture for cross-platform compatibility
  • Single cfg gate for sleep: gloo_timers::future::sleep (WASM) vs tokio::time::sleep (native)
  • OptionalCertificate type alias: Option<Certificate> on native, Option<()> on WASM
  • Moved expired-ban check to top of Phase 2 loop (fixes edge case where all bans expired before idle sleep)

rs-dapi-client/src/lib.rs:

  • Removed #[cfg(not(target_arch = "wasm32"))] from health_check module and HealthCheckConfig export

rs-dapi-client/Cargo.toml:

  • Moved tokio-util to non-gated deps with default-features = false

rs-sdk/src/sdk.rs:

  • start_health_check() now works on both platforms (tokio::spawn vs wasm_bindgen_futures::spawn_local)
  • build() uses single non-gated sdk.start_health_check() call — no duplicated spawn logic
  • Replaced Arc<ArcSwapOption<CancellationToken>> with Arc<Mutex<CancellationToken>> — simpler, no extra dep needed, token state is the state machine (cancelled = stopped, live = running)
  • Added stop_health_check(), is_health_check_running() for runtime control
  • Removed Drop impl and _health_check_handle field — lifecycle managed by CancellationToken

How Has This Been Tested?

  • cargo clippy -p dash-sdk -p rs-dapi-client — clean
  • cargo test -p dash-sdk --lib — 84 passed
  • cargo test -p rs-dapi-client — all passed
  • Existing tests cover: config defaults, cancel token stops loop, unreachable node detection, startup probe banning, empty address list, multi-node banning, probe settings validation, cancel during ban watch phase

Breaking Changes

None. Public API additions only (start_health_check, stop_health_check, is_health_check_running).

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

🤖 Co-authored by Claudius the Magnificent AI Agent

…ASM targets

Replace tokio-specific primitives with runtime-agnostic alternatives so the
health_check module is no longer gated behind #[cfg(not(target_arch = "wasm32"))].

- Use futures::select_biased! instead of tokio::select!
- cfg-gate only the sleep import (tokio::time::sleep vs gloo_timers::future::sleep)
- Move tokio-util to non-gated deps (CancellationToken needs no runtime)
- Split run_health_check into a thin public wrapper + inner health_check_loop
  that takes a generic stop future
- Add WASM health check spawning via wasm_bindgen_futures::spawn_local in rs-sdk
- Expose withHealthCheck() builder method in wasm-sdk
- Remove #[cfg(not(wasm32))] gates from health_check module and HealthCheckConfig export

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 17, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5221878c-4517-4a72-90dc-b2e2f910b53c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sdk-health-check-wasm
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 17, 2026

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "3472d896bdea8e9c095db4a686879be8aa45f50ee21ce3184ff10bb58bb6efce"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

lklimek and others added 2 commits March 17, 2026 13:04
Resolve conflicts:
- health_check.rs: combine WASM cross-platform structure (select_biased!,
  gloo_timers) with expired-ban-before-sleep fix from base
- sdk.rs: remove pre-extracted hc_* variables, use start_health_check()
- Make start_health_check() cross-platform (tokio::spawn vs spawn_local)
- Remove cfg gate from build() health check init

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lklimek lklimek changed the title feat(rs-dapi-client): make health check compile for both native and WASM targets feat(rs-dapi-client): make health check cross-platform (native + WASM) Mar 17, 2026
@lklimek lklimek marked this pull request as ready for review March 17, 2026 12:22
@lklimek lklimek merged commit 477cc39 into feat/sdk-health-check Mar 17, 2026
5 of 8 checks passed
@lklimek lklimek deleted the feat/sdk-health-check-wasm branch March 17, 2026 12:23
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.

1 participant