serverless: graceful-fs crashes with "RangeError: Maximum call stack size exceeded"

❗️ NOTE FROM MAINTAINERS ❗️

This issue is result of relying on non-latest (buggy) graceful-fs version, either directly or through other (not serverless) dependencies. serverless on its own expects latest version of graceful-fs to be installed.

Crash happens when two versions of graceful-fs are initialized and one of them is non-latest (buggy) version.

SOLUTION

Ensure project and its dependencies work only with latest graceful-fs version.

It usually can be solved by nuking node_modules and package-lock.json (or yarn.lock) and reinstalling the project.

When relying on Yarn package manager it can also be solved by adding following instruction to package.json

  "resolutions": {
    "graceful-fs": "4.2.2"
  }

and running yarn install (thanks @sheerun for this tip)


This is a Bug Report

Description

  • What went wrong? RangeError: Maximum call stack size exceeded while deploying
  • What did you expect should have happened? Deploy without problem
  • What stacktrace or error message from your provider did you see?
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:199:24)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)
      at WriteStream (/opt/atlassian/pipelines/agent/build/node_modules/graceful-fs/graceful-fs.js:201:29)

Similar or dependent issues:

  • #6653 is probably the origin of the problem

Additional Data

  • Serverless Framework Version you’re using: 1.52.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 66
  • Comments: 37 (13 by maintainers)

Commits related to this issue

Most upvoted comments

Same problem here. graceful-fs not being graceful.

@vitorfs it’s most likely caused by fact that at /codebuild/output/src942665664/src/node_modules/graceful-fs there’s non latest (and buggy) graceful-fs version installed.

Ensure to update dependencies of the project and issue should be fixed

~ Hat tip to ya good sir on pointing us in the right direction.

We ran into this issue on a pipeline build and got us head scratching for a bit. If doing this via ADO or Gitlab, ensure that you change the global serverless install during the build.

install -g serverless@1.51.0

From our side, we faced the same issue 30 min ago. If i can add some info to it, our packages such as serverless-bundle, etc, are using an outdated version of graceful-fs. Adding a direct dependency to the same Graceful-fs dependency version Serverless has: "graceful-fs": "^4.2.2", It should work for the time being, i know there may be prettier ways to fix it.

Nothing like testing in production. Jeez.

Just a quick update that the v1.52.2 release will provide a fix for this issue --> https://github.com/serverless/serverless/pull/6718

Also seeing this problem. Rolling back to 1.51.0 solved it for me.

To fix this issue downgrade serverless to previous version by running npm i -g serverless@1.51.0

Workaround is to add to package.json:

  "resolutions": {
    "graceful-fs": "4.2.2"
  }

and run yarn install

At first I did roll back to version 1.51.0 and it fixed the problem for me.

Then I followed @medikoo tip, about graceful-fs being outdated, and solved it by doing something else. I didn’t have graceful-fs as a primary dependency, but several other packages depended on it, using different versions.

I updated some packages and re-generated my package-lock.json and it solved my issue. Now I’m successfully using 1.52.0.

Was about to create a new issue when I realised that this could potentially be the place where I also report it.

I was on the latest version of serverless@1.52.0 and running serverless create threw the same issue.

Let me know if this should be in another issue.

My solution was to downgrade to 1.51.0

We ran into this issue this morning and added the following to our package.json to resolve the issue for now (npm based):

"dependencies": {
       "graceful-fs": "^4.2.2"
 }

@motoko89 I nuked my package.lock and node_modules folder and that worked for us.

I’ve updated main description with specific info on how this issue can be solved within a project

I had the exact same issue. You’ll need to roll back to a previous serverless version or you’ll need to make sure graceful-fs is updated to its latest version by updating packages that depend on it (my case were fs-extra and nyc besides serverless). I went for the latter.

I started facing the same issue inside a CodeBuild a couple of hours ago. If I roll back to version 1.51.0 it works normally.

[Container] 2019/09/11 15:09:31 Phase complete: PRE_BUILD State: SUCCEEDED 
[Container] 2019/09/11 15:09:31 Phase context status code:  Message:  
[Container] 2019/09/11 15:09:32 Entering phase BUILD 
[Container] 2019/09/11 15:09:32 Running command serverless package --stage $STAGE --verbose 
Serverless: Using Python specified in "runtime": python3.7 
Serverless: Packaging Python WSGI handler... 
Serverless: Generated requirements from /codebuild/output/src942665664/src/eskolare-backend/requirements.txt in /codebuild/output/src942665664/src/eskolare-backend/.serverless/requirements.txt... 
Serverless: Installing requirements from /root/.cache/serverless-python-requirements/f9922aa4f4dfc5b04a7923931a712149_slspyc/requirements.txt ... 
Serverless: Using download cache directory /root/.cache/serverless-python-requirements/downloadCacheslspyc 
Serverless: Running ... 
Serverless: Packaging service... 
Serverless: Excluding development dependencies... 
  
  Range Error -------------------------------------------- 
  
  RangeError: Maximum call stack size exceeded 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:216:24) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 

... +7000 lines 

      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at new WriteStream (/codebuild/output/src942665664/src/node_modules/graceful-fs/graceful-fs.js:218:29) 
      at Object.createWriteStream (/usr/local/lib/node_modules/serverless/node_modules/graceful-fs/graceful-fs.js:306:12) 
      at Package.zipFiles (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/zipService.js:80:23) 
      at resolveFilePathsAll.then.filePaths (/usr/local/lib/node_modules/serverless/lib/plugins/package/lib/packageService.js:120:12) 
      at tryCatcher (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/util.js:16:23) 
      at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:517:31) 
      at Promise._settlePromise (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:574:18) 
      at Promise._settlePromise0 (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:619:10) 
      at Promise._settlePromises (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/promise.js:699:18) 
      at _drainQueueStep (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:138:12) 
      at _drainQueue (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:131:9) 
      at Async._drainQueues (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:147:5) 
      at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/serverless/node_modules/bluebird/js/release/async.js:17:14) 
      at runCallback (timers.js:705:18) 
      at tryOnImmediate (timers.js:676:5) 
      at processImmediate (timers.js:658:5) 
      at process.topLevelDomainCallback (domain.js:126:23) 
  
     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable. 
  
  Get Support -------------------------------------------- 
     Docs:          docs.serverless.com 
     Bugs:          github.com/serverless/serverless/issues 
     Issues:        forum.serverless.com 
  
  Your Environment Information --------------------------- 
     Operating System:          linux 
     Node Version:              10.16.0 
     Framework Version:         1.52.0 
     Plugin Version:            2.0.0 
     SDK Version:               2.1.1 
  
 
[Container] 2019/09/11 15:10:04 Command did not exit successfully serverless package --stage $STAGE --verbose exit status 1 
[Container] 2019/09/11 15:10:04 Phase complete: BUILD State: FAILED 
[Container] 2019/09/11 15:10:04 Phase context status code: COMMAND_EXECUTION_ERROR Message: Error while executing command: serverless package --stage $STAGE --verbose. Reason: exit status 1 

It is happening to me as well full logs

@hrnn Presented log is unrelated to this issue

~It is happening to me as well full logs~

Solved by updating package-lock.json as other mentioned here.

@vitorfs it’s most likely caused by fact that at /codebuild/output/src942665664/src/node_modules/graceful-fs there’s non latest (and buggy) graceful-fs version installed.

Ensure to update dependencies of the project and issue should be fixed