fix: add timeout to handleNodeTopup and parse response body in spawnP… #485
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
handleNodeTopupThe function contained two
do-whileloops 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-whileloops withforloops that have maximum retry limits (150 attempts = 5 minutes at 2s intervals), following the same pattern used inhandleRelayTopupfunction.Bug #2: Unparsed Response Body in
spawnProcessMainnetThe function attempted to access the
processproperty directly on the Response object without parsing the response body first, causing process spawning to fail silently.Fix:
accept: 'application/json'header to request params.map(prop('body')).map(JSON.parse)) before accessing theprocessproperty, following the same pattern used insendMessageMainnetfunctionChanges Made
src/services/mainnet.js:do-whileloop withforloop and retry limitdo-whileloop withforloop, retry limit, and delay between checksaccept: 'application/json'header tospawnProcessMainnetparamsprocessIDTesting
handleRelayTopupfor Bug 1,sendMessageMainnetfor Bug 2)Impact
Note: These fixes follow the existing code patterns in the codebase and maintain backward compatibility.