Skip to content

Conversation

@brukasom
Copy link

@brukasom brukasom commented Dec 18, 2025

Description

This PR fixes two critical bugs in the mainnet service that prevent users from successfully using AOS with mainnet:

Bug #1: Infinite Loop in handleNodeTopup

The function contained two do-while loops that could run indefinitely if balance updates were delayed, causing the process to hang on "Transferring balance to node..." with no way to recover.

Fix: Replaced both do-while loops with for loops that have maximum retry limits (150 attempts = 5 minutes at 2s intervals), following the same pattern used in handleRelayTopup function.

Bug #2: Unparsed Response Body in spawnProcessMainnet

The function attempted to access the process property directly on the Response object without parsing the response body first, causing process spawning to fail silently.

Fix:

  • Added accept: 'application/json' header to request params
  • Added response body parsing (.map(prop('body')).map(JSON.parse)) before accessing the process property, following the same pattern used in sendMessageMainnet function

Changes Made

  • src/services/mainnet.js:
    • Lines 417-441: Replaced first infinite do-while loop with for loop and retry limit
    • Lines 462-490: Replaced second infinite do-while loop with for loop, retry limit, and delay between checks
    • Line 154: Added accept: 'application/json' header to spawnProcessMainnet params
    • Lines 173-175: Added response body parsing before extracting process ID

Testing

  • Code follows existing patterns (handleRelayTopup for Bug 1, sendMessageMainnet for Bug 2)
  • No linter errors
  • Changes are minimal and focused on fixing the specific bugs

Impact

  • Bug 1: Prevents infinite hangs during topup, provides clear error messages and timeout handling
  • Bug 2: Enables process spawning on mainnet to work correctly

Note: These fixes follow the existing code patterns in the codebase and maintain backward compatibility.

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