trufflesuite / ganache-ui

Personal blockchain for Ethereum development
https://www.trufflesuite.com/ganache
MIT License
4.65k stars 794 forks source link

ENOENT: no such file or directory, stat chaindata\!trie_db!0x... #1374

Open wbt opened 5 years ago

wbt commented 5 years ago

In recent dapp development, I recently saw a case where a small programming bug put a ++ on the termination rather than increment condition of a for loop, making it an infinite loop. It should have been a relatively minor typo in a rapid prototyping/test cycle.

The limited contents of the loop only involved reading from the DOM and console logging, with no blockchain interaction, though entry into the loop is triggered by user interaction and a blockchain event. However, stopping this loop was surprisingly hard. The code was quickly corrected and a page reload initiated, but CPU use remained quite high. Even closing the browser tab didn't stop things. In Windows Task Manager, Ganche and Chrome CPU usage remained very high. I don't know why Ganache had high CPU at that time, as there was no blockchain reading or interaction in the loop. I quit Ganache but Chrome's CPU use remained high. Even a number of minutes after quitting Chrome, its background "Software Reporter Tool" processes remained at high CPU usage, but eventually died down.

Later, I attempted to restart Ganache. It took minutes before anything came up. Once it did and I could select the workspace, I noticed that all accounts had 0 ETH, which had not previously been the case. Clicking Contracts showed "No projects in workspace" which also had not been the case before. Soon thereafter, there was an "Uh Oh...That's a bug" message pretty quick, and the "Raise GitHub issue" button autopopulated this information, names changed for privacy:


System Error when running Ganache 2.1.0 on win32

PLATFORM: win32 GANACHE VERSION: 2.1.0

EXCEPTION:

Error: ENOENT: no such file or directory, stat 'C:\Users\username\AppData\Roaming\Ganache\workspaces\myworkspace\chaindata\!trie_db!0x6563a1f2b2159aba8db7d9846b9554d6f019a92ee25e37d1149f049426a9dc2c'
    at fs.statSync (fs.js:960:11)
    at Object.fs.statSync (ELECTRON_ASAR.js:279:16)
    at Object.statSync (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\graceful-fs\polyfills.js:295:24)
    at checkStats (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:171:22)
    at checkPaths (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:183:31)
    at copyDirItem (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:117:20)
    at fs.readdirSync.forEach.item (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:111:39)
    at Array.forEach (<anonymous>)
    at copyDir (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:111:23)
    at onDir (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:101:10)
    at getStats (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:43:37)
    at startCopy (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:36:10)
    at copyDirItem (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:118:10)
    at fs.readdirSync.forEach.item (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:111:39)
    at Array.forEach (<anonymous>)
    at copyDir (C:\Users\username\AppData\Local\Programs\Ganache\resources\app.asar\node_modules\fs-extra\lib\copy-sync\copy-sync.js:111:23)

This seems like it might be related to #1277, a reportedly fixed problem, still present in a version later than the one in which it was fixed.

The next relaunch was faster, but the workspace I'd been using was gone, and replaced in the list by one called "Quickstart." It also had no ETH in any account and no associated projects, though it showed lots of blocks had been mined. I relaunched and clicked to delete the Quickstart workspace. Clicking to confirm removal, the application went unresponsive and a partially transparent white box covered the Ganache UI, for about a minute. I then clicked New Workspace, set a name and added a truffle project, and clicked Save Workspace, which took me to an Accounts list that had the tabs and status bar at the top, with the mnemonic underneath, and about a minute later, an accounts list. I recompiled and remigrated (truffle migrate --reset for the latter); the migration runs thousands of transactions. Most of those are in the final migration which just has contract interactions (no deployments), which does some logging that went through like usual, though Truffle reported "Total cost: 0 ETH."

Ganache still showed all the accounts as having default balance of 100.00 ETH and no transactions. Switching to the Contracts tab, the contract addresses slowly updated; switching back to the Accounts tab I saw the total ETH usage had been just 0.41 ETH with just 61 transactions. Under the Contracts tab, contracts were listed with TX counts in the dozens, not in the hundreds or thousands. Switching between Contracts and Accounts tabs took minutes, even though each had <25 list items. Reopening Chrome and connecting via MetaMask, the dapp reported that web3.eth.getBlock ('latest'...) was resolving to null.

I then clicked "switch" to change workspaces. Ganache stopped responding (with "Not Responding" in the title bar) for a couple minutes, then went back to the Workspaces selection screen. I re-entered the workspace and after about a minute waiting, saw an Accounts list with a tx count and balance list more like what I'd expected. Clicking the Contracts tab, most had "Not Deployed" under the address now. I got the same errors from the dapp about a null latestBlock.

I clicked again to Switch workspaces, which worked right away this time, and deleted all workspaces, one at a time. I created and configured a new one, recompiled and remigrated, and saw complete lack of UI updating about balances and tx counts and slow changes between tabs.

It is very unclear what's happening here and I don't have detailed steps to reproduce, but there seems to be at least one bug. The stack trace above may provide some recognition support for fixing at least one bug. Some of the details above are probably irrelevant but I'm not completely sure which ones.

In general, Ganache also seems less stable than it used to be, and frequently has long delays between any interaction trigger and response. I suspect use of Ganache might be causing this MetaMask issue which I still frequently observe.

davidmurdoch commented 5 years ago

Did you Quit Ganache or Kill the Ganache process?

wbt commented 5 years ago

I don't recall for the first occasion with the infinite loop, but Quit (X in the upper right corner) for the other cases.