Skip to content

fix(txm): heap out of memory#573

Merged
GabrielMartinezRodriguez merged 2 commits into
masterfrom
gabriel/fix-txm-heap-out-of-memory
Apr 13, 2025
Merged

fix(txm): heap out of memory#573
GabrielMartinezRodriguez merged 2 commits into
masterfrom
gabriel/fix-txm-heap-out-of-memory

Conversation

@GabrielMartinezRodriguez

@GabrielMartinezRodriguez GabrielMartinezRodriguez commented Mar 28, 2025

Copy link
Copy Markdown
Contributor

Description

This PR solves an issue that causes the TXM to crash whenever there's a connection problem with the node due to a heap out-of-memory error. The crash was happening because timers were not being cleared, and while the node was down, we entered an infinite loop: onError -> resetBlockSubscription -> start -> onError. In each iteration, we left timers uncleared, quickly filling up the 4GB heap available to the process.

To fix this, we now clear the timers on every iteration. Additionally, we wait 500ms before retrying the connection to give the node some time to recover

image

In this chart, you can see the process uptime. Every time it drops to zero, it indicates a restart, which was caused by this issue

Toggle Checklist

Checklist

Basics

  • B1. I have applied the proper label & proper branch name (e.g. norswap/build-system-caching).
  • B2. This PR is not so big that it should be split & addresses only one concern.
  • B3. The PR targets the lowest branch it can (ideally master).

Reminder: PR review guidelines

Correctness

  • C1. Builds and passes tests.
  • C2. The code is properly parameterized & compatible with different environments (e.g. local,
    testnet, mainnet, standalone wallet, ...).
  • C3. I have manually tested my changes & connected features.

< INDICATE BROWSER, DEMO APP & OTHER ENV DETAILS USED FOR TESTING HERE >

< INDICATE TESTED SCENARIOS (USER INTERFACE INTERACTION, CODE FLOWS) HERE >

  • C4. I have performed a thorough self-review of my code after submitting the PR,
    and have updated the code & comments accordingly.

Architecture & Documentation

  • D1. I made it easy to reason locally about the code, by (1) using proper abstraction boundaries,
    (2) commenting these boundaries correctly, (3) adding inline comments for context when needed.
  • D2. All public-facing APIs & meaningful (non-local) internal APIs are properly documented in code
    comments.
  • D3. If appropriate, the general architecture of the code is documented in a code comment or
    in a Markdown document.
  • D4. An appropriate Changeset has been generated (and committed) for changes that touch npm published packages (currently packages/core and packages/react), see here for more info.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Mar 28, 2025

Copy link
Copy Markdown

Deploying happychain with  Cloudflare Pages  Cloudflare Pages

Latest commit: d3a8679
Status:⚡️  Build in progress...

View logs

@GabrielMartinezRodriguez GabrielMartinezRodriguez added the reviewing-1 Ready for, or undergoing first-line review label Mar 28, 2025

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a heap out of memory issue in the BlockMonitor module by refining the block reset logic.

  • Adds checks to clear an existing block timeout before scheduling a new one.
  • Ensures proper cleanup of the unwatch callback before rescheduling block monitor start.

Comment thread packages/txm/lib/BlockMonitor.ts Outdated
@aodhgan aodhgan added merge-blocked Ready to merge, waiting for downstack and removed reviewing-1 Ready for, or undergoing first-line review labels Apr 1, 2025
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 1a9913d to be3a812 Compare April 3, 2025 11:18
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from d9ca14c to 0563ec5 Compare April 3, 2025 11:18
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from be3a812 to f709674 Compare April 3, 2025 11:37
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch 2 times, most recently from f8961b8 to 4b1dec2 Compare April 3, 2025 13:07
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from aa20cdc to 34ecd78 Compare April 8, 2025 13:01
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 49ca1f5 to 98ddf67 Compare April 10, 2025 07:52
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 34ecd78 to a5a0a16 Compare April 10, 2025 07:52
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 98ddf67 to 7d6b4d7 Compare April 10, 2025 08:01
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from a5a0a16 to 7bd96c6 Compare April 10, 2025 08:01
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 7d6b4d7 to c0e9e96 Compare April 10, 2025 08:37
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 7bd96c6 to 1952e64 Compare April 10, 2025 08:38
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from c0e9e96 to 709b75c Compare April 10, 2025 08:51
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 1952e64 to ff6ba03 Compare April 10, 2025 08:51
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 709b75c to 538a0a1 Compare April 10, 2025 09:12
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from ff6ba03 to 9b6be7f Compare April 10, 2025 09:13
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 538a0a1 to 93e241c Compare April 10, 2025 09:56
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch 3 times, most recently from cf6a8e8 to d388440 Compare April 10, 2025 11:56
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from 42bc0db to ceb064f Compare April 13, 2025 21:30
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from d388440 to 3e362df Compare April 13, 2025 21:30
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/avoid-create-new-attempts branch from ceb064f to 7a35565 Compare April 13, 2025 21:36
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel/fix-txm-heap-out-of-memory branch from 3e362df to 48d79d7 Compare April 13, 2025 21:36
Base automatically changed from gabriel/avoid-create-new-attempts to master April 13, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-blocked Ready to merge, waiting for downstack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants