Skip to content

peering: bound the buyer invoice queue so a slow wallet cannot grow memory without limit #1230

Done

Description

@Ferryx349

Context

Follow-up from the review of #1169 (PR #1169). subscribeToInvoices insrc/app/peering-sync-worker.ts appends every kind-402 invoice event to a promise chain:

this.invoiceHandling = this.invoiceHandling
  .then(() => this.handleInvoiceEvent(event))
  .catch((error) => { ... })

Problem

Each event and its promise stay in memory until every earlier invoice handler has finished. handleInvoiceEvent can call buyerService.handleInvoice, which performs wallet/processor I/O (payInvoice, invoice lookups) and database transactions.

If the wallet is slow or hanging, the chain falls behind. A peer that keeps publishing invoice events then grows the queue without bound. Unlike the live feed queue, the invoice path has no count or byte limit and never closes the connection:

  • Live feed: PEERING_SYNC_MAX_PENDING_EVENTS (500) and PEERING_SYNC_MAX_PENDING_EVENT_BYTES (8 MiB); exceeding either logs a warning and reconnects.
  • Invoice path: unbounded; queued wallet calls can pile up indefinitely.

Effects:

  • Unbounded memory growth per peer.
  • Wallet/processor work queued long after the triggering event.
  • A peer credential can be used as a resource-abuse/egress vector.

Activity

  1. added
    security
    on Nov 22, 2026
  2. self-assigned this
    on Nov 22, 2026
  3. added a commit that references this issue on Nov 29, 2026
    b77a457
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

peeringsecurity

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions