Skip to content

fix: Add reentrancy guard to _startInvoicePaymentMonitoring periodic timer #57

@coderabbitai

Description

@coderabbitai

Summary

The _startInvoicePaymentMonitoring method in lib/screens/9receive_screen.dart uses a Timer.periodic callback that fires every 2 seconds without waiting for the previous checkInvoiceStatus HTTP call to complete. Since checkInvoiceStatus can have timeouts of 20–30 seconds, multiple callbacks can overlap and create concurrent redundant requests.

Proposed Fix

Add a private boolean field _isCheckingInvoiceStatus as a reentrancy guard:

bool _isCheckingInvoiceStatus = false;

// Inside the Timer.periodic callback:
if (_isCheckingInvoiceStatus) return;
_isCheckingInvoiceStatus = true;
try {
  // ... checkInvoiceStatus call ...
} catch (e) {
  // ... error handling ...
} finally {
  _isCheckingInvoiceStatus = false;
}

Also ensure _invoicePaymentTimeoutTimer is cancelled and nulled when the invoice is confirmed paid inside the periodic callback.

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions