Skip to content

fix: add timeout and recovery to Spark wallet initialization#3563

Merged
TaprootFreak merged 1 commit intodevelopfrom
fix/spark-init-timeout
Apr 9, 2026
Merged

fix: add timeout and recovery to Spark wallet initialization#3563
TaprootFreak merged 1 commit intodevelopfrom
fix/spark-init-timeout

Conversation

@TaprootFreak
Copy link
Copy Markdown
Collaborator

Summary

  • Add 60s timeout per SparkWallet.initialize() attempt — if the SDK promise hangs due to a WASM-layer crash, the timeout rejects and the retry loop continues
  • Extract initializeWithTimeout() to race SDK initialization against a timer
  • Add resetWallet() method for external recovery (e.g. from uncaughtException handler)
  • Minor readability improvement to uncaughtException handler

Context

Follow-up to #3561. The Spark SDK can throw SparkAuthenticationError from a gRPC timer callback (outside the Promise chain), which the uncaughtException handler catches. However, SparkWallet.initialize() remains as an unresolved promise, causing all subsequent await this.wallet calls to hang forever. The timeout ensures the retry loop can recover from this state.

Test plan

  • Verify API starts when Spark is unreachable (wallet retries with timeout, API serves other endpoints)
  • Verify Spark reconnects automatically once gRPC server recovers
  • Verify resetWallet() triggers re-initialization

The Spark SDK can throw uncatchable errors from its WASM/gRPC layer via
timer callbacks, leaving SparkWallet.initialize() hanging as an
unresolved promise. This causes all Spark operations to block forever.

- Add 60s timeout per initialization attempt so hanging promises fail
  and the retry loop can continue
- Extract initializeWithTimeout() to race initialization against timer
- Add resetWallet() method for external recovery triggers
- Improve uncaughtException handler readability
@TaprootFreak TaprootFreak marked this pull request as ready for review April 9, 2026 21:05
@TaprootFreak TaprootFreak merged commit e4a79cb into develop Apr 9, 2026
7 checks passed
@TaprootFreak TaprootFreak deleted the fix/spark-init-timeout branch April 9, 2026 21:05
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 2026

❌ Security: 3 critical vulnerabilities

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