diff --git a/packages/concordia-pinner/src/index.js b/packages/concordia-pinner/src/index.js index c23d648..f2d7743 100644 --- a/packages/concordia-pinner/src/index.js +++ b/packages/concordia-pinner/src/index.js @@ -10,13 +10,19 @@ import downloadContractArtifacts from './utils/drizzleUtils'; import getIpfsOptions from './options/ipfsOptions'; import { logger } from './utils/logger'; -process.on('unhandledRejection', (error) => { +let ipfsSingleton; + +process.on('unhandledRejection', async (error) => { // This happens when attempting to initialize without any available Swarm addresses (e.g. Rendezvous) if (error.code === 'ERR_NO_VALID_ADDRESSES') { logger.error(`unhandledRejection: ${error.message}`); process.exit(1); } + if (ipfsSingleton) { + await ipfsSingleton.stop(); + } + // Don't swallow other errors logger.error(error); throw error; @@ -71,6 +77,10 @@ const main = async () => { getDeployedContract(web3) .then(({ contract, contractAddress }) => getIpfsOptions() .then((ipfsOptions) => IPFS.create(ipfsOptions)) + .then((ipfs) => { + ipfsSingleton = ipfs; + return ipfs; + }) .then((ipfs) => createOrbitInstance(ipfs, contractAddress)) .then((orbit) => openExistingUsersDatabases(contract, orbit) .then(() => { diff --git a/yarn.lock b/yarn.lock index 43f21aa..0cf9450 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16469,6 +16469,9 @@ snake-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/snake-case/-/snake-case-3.0.4.tgz#4f2bbd568e9935abdfd593f34c691dadb49c452c" integrity sha512-LAOh4z89bGQvl9pFfNF8V146i7o7/CqFPbqzYgP+yYzDIDeS9HaNFtXABamRW+AQzEVODcvE79ljJ+8a9YSdMg== + dependencies: + dot-case "^3.0.4" + tslib "^2.0.3" snapdragon-node@^2.0.1: version "2.1.1"