Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

fix: race condition causing Database is not open error #1834

Merged
merged 1 commit into from
Jan 21, 2019

Commits on Jan 21, 2019

  1. fix: race condition causing Database is not open error

    [`cleanup`](https://github.com/ipfs/js-ipfs/blob/7d9b006d0b0542651cbaa540d5f22a0112ae09bd/src/cli/bin.js#L109) closes the DB but `yargs-promise` does not wait for async stuff in the command handler to finish, and executes that promise chain immediately after the handler is executed. So it's a race condition. In windows, _sometimes_, the database is closed before the async stuff from the handler completes.
    
    This PR changes the CLI command handlers to always pass a promise to `resolve` function that `yargs-promise` adds to the context (`argv`). This makes `yargs-promise` wait for it to be resolved before continuing the promise chain and closing the DB.
    
    Since I had to edit all of the commands to make them use the `resolve` function and introduce promises, I decided to take the opportunity to refactor the CLI commands to use async/await. It should help towards #1670.
    
    License: MIT
    Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
    Alan Shaw committed Jan 21, 2019
    Configuration menu
    Copy the full SHA
    f34df6f View commit details
    Browse the repository at this point in the history