gkz / grasp

JavaScript structural search, replace, and refactor
http://graspjs.com
MIT License
1.28k stars 33 forks source link

segmentation fault when run on large sets of files #128

Open chriswatrous opened 6 years ago

chriswatrous commented 6 years ago

I'm getting Segmentation fault: 11 and sometimes Bus error: 10 when running grasp on large sets of files. I first noticed the problem working on a proprietary project that I can't share here but I was able to reproduce it by cloning the react repo.

To reproduce:

git clone https://github.com/facebook/react.git --branch v16.4.2 --depth 1
cd react
grasp -r ident
grasp -r import-dec
grasp -r with
grasp -re '__ = __'
grasp -re '__ = __ = __'

This gets 131643 lines of javascript. The query doesn't seem to matter. All of those grasp commands end with Segmentation fault: 11 every time.

Here's an example with a smaller set of files (but still 29065 lines).

cd packages/react-dom/src/__tests__

# run grasp on 29066 lines in 67 files
grasp with *.js # segfault

# run grasp separately on each file, largest file 2578 lines
ls *.js | xargs -L 1 grasp with  # no segfault

# cat the files together and pipe to grasp
cat *.js | grasp with  # segfault
ainthek commented 6 years ago

same problem here running on node.js codebase:

$ grasp -e '__.pop' -r ../node/lib/
lib/domain.js:247:        stack.pop();
lib/internal/assert.js:74:    actualLines.pop();
lib/internal/assert.js:75:    expectedLines.pop();
lib/internal/assert.js:176:        actualLines.pop();
lib/internal/assert.js:241:            res.pop();
lib/internal/freelist.js:13:      this.list.pop() :
Segmentation fault: 11
ainthek commented 6 years ago

chriswatrous: try $ node --version v10.7.0 works for me

chriswatrous commented 6 years ago

Cool. It works for me with node v10.7.0.

I made this shell script so I can use it while other node versions are active:

~/bin/grasp

#!/bin/bash

~/.nvm/versions/node/v10.7.0/bin/node ~/.nvm/versions/node/v10.7.0/lib/node_modules/grasp/bin/grasp "$@"

An alias also works:

alias grasp='~/.nvm/versions/node/v10.7.0/bin/node ~/.nvm/versions/node/v10.7.0/lib/node_modules/grasp/bin/grasp'