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

Ganache crashes when running truffle debug #332

Closed
wesleyfsmith opened this issue Feb 24, 2019 · 12 comments
Closed

Ganache crashes when running truffle debug #332

wesleyfsmith opened this issue Feb 24, 2019 · 12 comments

Comments

@wesleyfsmith
Copy link

I am running ganache 1.3

My test code appears to run successfully, and I am able to see the transaction appear in ganache. However, when I run truffle debug txId I get the following error:

RangeError: Invalid string length
    at JSON.stringify (<anonymous>)
    at /node_modules/ganache-core/lib/httpServer.js:103:57
    at Object.intermediary [as callback] (/node_modules/ganache-core/lib/provider.js:114:5)
    at self.engine.sendAsync (/node_modules/ganache-core/lib/provider.js:169:12)
    at /node_modules/ganache-core/node_modules/web3-provider-engine/index.js:152:9
    at /node_modules/ganache-core/node_modules/async/internal/once.js:12:16
    at replenish (/node_modules/ganache-core/node_modules/async/internal/eachOfLimit.js:61:25)
    at /node_modules/ganache-core/node_modules/async/internal/eachOfLimit.js:71:9
    at eachLimit (/node_modules/ganache-core/node_modules/async/eachLimit.js:43:36)
    at /node_modules/ganache-core/node_modules/async/internal/doLimit.js:9:16
    at Object.end [as callback] (/node_modules/ganache-core/node_modules/web3-provider-engine/index.js:127:5)
    at intermediary (/node_modules/ganache-core/lib/statemanager.js:401:12)
    at /node_modules/ganache-core/lib/blockchain_double.js:900:11
    at /node_modules/ganache-core/lib/blockchain_double.js:649:9
    at commmitIfNeeded (/node_modules/ganache-core/lib/blockchain_double.js:640:11)
    at /node_modules/ganache-core/lib/blockchain_double.js:644:7
    at /node_modules/ganache-core/node_modules/async/internal/once.js:12:16
    at replenish (/node_modules/ganache-core/node_modules/async/internal/eachOfLimit.js:61:25)
    at /node_modules/ganache-core/node_modules/async/internal/eachOfLimit.js:71:9
    at eachLimit (/node_modules/ganache-core/node_modules/async/eachLimit.js:43:36)
    at /node_modules/ganache-core/node_modules/async/internal/doLimit.js:9:16
    at VM.AsyncEventEmitter.emit (/node_modules/ganache-core/node_modules/async-eventemitter/lib/AsyncEventEmitter.js:42:3)

This error occurs when debugging any transaction and causes ganache to crash.

Currently running macOS Mojave 10.14

@eshaben
Copy link
Contributor

eshaben commented Feb 25, 2019

Possibly related to /issues/630

@wesleyfsmith
Copy link
Author

I originally thought that it might be because I was using the experimental abi encoder, but I refactor my code to no longer use the experimental abi, and I still am getting this issue on some of my transactions.

@davidmurdoch
Copy link
Member

@wesleyfsmith Is it possible for you to provide reproduction steps?

@inukaeth
Copy link

inukaeth commented Jul 2, 2019

I am hitting the same issue.

In my case my contract is large and I am running Ganache with allowUnlimitedContractSize:true. This maybe a contributing factor.

Ganache version 2.0.1
Truffle version:
Truffle v5.0.25 (core: 5.0.25)
Solidity v0.5.0 (solc-js)
Node v8.11.2
Web3.js v1.0.0-beta.37

Thanks

@nicholasjpaterno
Copy link
Contributor

nicholasjpaterno commented Jul 2, 2019

@inukaeth Have you tried adjusting the block gasLimit? Its a common issue (not a bug) with allowUnlimitedContractSize where users are attempting to deploy with greater gas requirements than the current block limit.

@davidmurdoch
Copy link
Member

@inukaeth if adjusting the gasLimit doesn't work for you could provide reproduction steps/repo here so we can track down the issue?

@davidmurdoch
Copy link
Member

I believe this happens when the data ganache attempts to send back to the client is too large for the current node process to JSON.stringify; it just runs out of available memory. One way to solve this is to start the ganache server process with more memory (--max-old-space-size=8192), another is for ganache to implement #381 and from truffle debug to use it.

@dkelsen
Copy link

dkelsen commented Dec 28, 2020

Getting this error as well and I'm working on a mainnet fork.

    at JSON.stringify (<anonymous>)
    at /Users/dilshan/.nvm/versions/node/v14.15.1/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:94:95383
    at /Users/dilshan/.nvm/versions/node/v14.15.1/lib/node_modules/ganache-cli/build/ganache-core.node.cli.js:42:14963
    at processTicksAndRejections (internal/process/task_queues.js:75:11)

@gnidan
Copy link
Contributor

gnidan commented Feb 24, 2021

Node.js has a hard limit on the size of strings, that might be the problem here. @davidmurdoch also reports that JSON.stringify has its own string length limit. Could anyone here provide more precise reproduction steps?

Barring that, we can probably see about reproducing this error by attempting to debug_traceTransaction on a transaction ≥6M gas or so.

If the problem here is with JSON.stringify itself and not Node's unavoidable limit, @davidmurdoch reports a possible solution he found here.

Thanks all! Hopefully we'll be able to sort this one out.

@Gdocal
Copy link

Gdocal commented Mar 10, 2021

I get this issue often. I use brownie + ganache-cli, when tx reverts (gas usage: 2m) brwonie sends debug_traceTransaction, and ganache crashes after this

file ganache-core.node.cli.js
switch (o) { case "POST": var d; try { d = JSON.parse(f); } catch (e) { return (s["Content-Type"] = "text/plain"), void c(n, 400, s, "400 Bad Request"); } if (d instanceof Array) for (var u = 0; u < d.length; u++) { var b = d[u]; t.log(b.method); } else t.log(d.method); if ("eth_subscribe" === d.method || "eth_unsubscribe" === d.method) { (s["Content-Type"] = "application/json"), c(n, 400, s, a(d.id, -32e3, "notifications not supported")); break; } e.send(d, function (e, t) { (s["Content-Type"] = "application/json"), c(n, 200, s, JSON.stringify(t)); //<---------------- CRASHED HERE }); break; case "OPTIONS": c(n, 204, s); break; default: (s["Content-Type"] = "text/plain"), c(n, 400, s, "400 Bad Request"); } });

@jeffywu
Copy link

jeffywu commented May 25, 2021

Is this where the provider returns data to the client?

https://github.com/trufflesuite/ganache-core/blob/6ec151bca2a4f3c7815869529b507333fe1611c5/src/chains/ethereum/ethereum/src/provider.ts#L214

Wondering if it would be feasible to use JSONStream there instead of JSON.stringify, but I can't say that I'm very familiar with how the code works.
https://www.npmjs.com/package/JSONStream

@davidmurdoch
Copy link
Member

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants