Skip to content

feat(sdk): implement global timeout for multi-node failover loops#951

Open
Hallab7 wants to merge 1 commit intodotandev:mainfrom
Hallab7:feat/sdk-global-timeout
Open

feat(sdk): implement global timeout for multi-node failover loops#951
Hallab7 wants to merge 1 commit intodotandev:mainfrom
Hallab7:feat/sdk-global-timeout

Conversation

@Hallab7
Copy link
Copy Markdown
Contributor

@Hallab7 Hallab7 commented Mar 26, 2026

PULL REQUEST TEMPLATE

TITLE:

feat(sdk): implement global timeout for multi-node failover loops

DESCRIPTION:

Overview

Implements global timeout functionality for multi-node failover operations to prevent excessively long operations when all RPC nodes are slow. Adds TotalTimeout configuration option that caps the total time spent across all nodes during failover loops.

Changes

Core Implementation

  • NetworkConfig Enhancement: Added TotalTimeout time.Duration field to Go SDK NetworkConfig
  • RPCConfig Enhancement: Added totalTimeout?: number field to TypeScript SDK RPCConfig
  • Builder Option: New WithTotalTimeout() function for Go SDK client configuration
  • Default Values: 60-second default timeout for all predefined network configurations
  • Context Management: Uses context.WithTimeout() for Go and Promise.race() for TypeScript
  • Failover Methods Updated: Applied to GetTransaction, GetLedgerHeader, SimulateTransaction, GetHealth, and GetLedgerEntries

Go SDK Implementation

  • Modified failover loops in GetTransaction, GetLedgerHeader, SimulateTransaction, GetHealth methods
  • Added context cancellation checks between node attempts
  • Proper timeout error handling with descriptive messages
  • Backward compatible with existing NetworkConfig usage

TypeScript SDK Implementation

  • Updated FallbackRPCClient.executeFallback() method with timeout enforcement
  • Timeout implementation using Promise.race() pattern
  • Elapsed time checking between endpoint attempts
  • Maintains existing middleware and retry functionality

Testing

  • Unit Tests: Comprehensive timeout scenarios in timeout_test.go
  • Integration Tests: Failover timeout validation in fallback-client-timeout.test.ts
  • Factory Tests: Builder option functionality and configuration validation
  • Coverage: All timeout paths, success cases, disabled timeout, and edge cases

Documentation

  • GLOBAL_TIMEOUT.md: Complete technical specification
  • Configuration examples for both Go and TypeScript SDKs
  • Error handling patterns and best practices
  • Migration guidance for existing code
  • Security properties and behavior documentation

Security Properties

  • No Breaking Changes: Existing code continues to work unchanged
  • Reasonable Defaults: 60-second timeout provides protection without restriction
  • Proper Cancellation: Clean context/promise cancellation on timeout
  • Error Transparency: Clear timeout error messages for debugging

Configuration

Required configuration options:

  • Go SDK: TotalTimeout time.Duration in NetworkConfig or WithTotalTimeout() builder option
  • TypeScript SDK: totalTimeout: number in RPCConfig (milliseconds)
  • Default: 60 seconds for both SDKs

Timeout Behavior

Global timeout enforcement:

  • Enabled: Operation cancelled when global timeout exceeded across all nodes
  • Disabled: Set to 0 to use existing behavior (no global limit)
  • Default: 60-second timeout applied automatically to predefined network configs
  • Individual Timeouts: Still respected per-request within global limit

Verification

  • All existing tests continue to pass
  • New timeout tests validate expected behavior across multiple scenarios
  • No performance impact on successful operations
  • Backward compatible with all existing configurations
  • Code follows DRY principles
  • Zero conversational filler in implementation
  • Ready for production deployment

Related Issues

closes #894

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Tests added/updated
  • Documentation updated
  • No new linting issues
  • Changes verified locally
    ================================================================================

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

@Hallab7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

[SDK] Implement 'Global Timeout' for multi-node failover loops

1 participant