gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.3k stars 10.31k forks source link

Crash during hot reload - ERROR UNHANDLED REJECTION request to http://localhost:8000/___graphql #16469

Closed mduecker closed 5 years ago

mduecker commented 5 years ago

Description

Since yesterday gatsby develop will crash every time I make a change to an existing file with an error message (see below).

Steps to reproduce

Every time I make a change with gatsby develop running, the process will crash. I'll see if I can make a reproducible example, without sharing my full project

Expected result

After making a change in gatsby develop mode, Gatsby should hot reload and show the updated page.

Actual result

After showing the status "Compiling..." the process crashes with the following error:

UNHANDLED REJECTION request to http://localhost:8000/___graphql failed, reason: getaddrinfo ENOTFOUND localhost localhost:8000

FetchError: request to http://localhost:8000/___graphql failed, reason: getaddrinfo ENOTFOUND localhost localhost:8000

  • index.js:1455 ClientRequest. [ts-gatsby]/[gatsby-cli]/[node-fetch]/lib/index.js:1455:11

Environment

System: OS: macOS 10.14.3 CPU: (8) x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz Shell: 5.3 - /bin/zsh Binaries: Node: 10.16.2 - ~/.nvm/versions/node/v10.16.2/bin/node Yarn: 1.16.0 - /usr/local/bin/yarn npm: 6.9.0 - ~/.nvm/versions/node/v10.16.2/bin/npm Languages: Python: 2.7.10 - /usr/bin/python npmPackages: gatsby: 2.13.25 => 2.13.25 gatsby-background-image: 0.7.6 => 0.7.6 gatsby-image: 2.2.6 => 2.2.6 gatsby-plugin-antd: 2.0.2 => 2.0.2 gatsby-plugin-exclude: 1.0.0 => 1.0.0 gatsby-plugin-facebook-analytics: 2.2.2 => 2.2.2 gatsby-plugin-google-analytics: 2.1.4 => 2.1.4 gatsby-plugin-hotjar: 1.0.1 => 1.0.1 gatsby-plugin-intercom: 0.1.4 => 0.1.4 gatsby-plugin-less: 2.1.2 => 2.1.2 gatsby-plugin-lodash: 3.1.2 => 3.1.2 gatsby-plugin-manifest: 2.2.3 => 2.2.3 gatsby-plugin-offline: 2.2.4 => 2.2.4 gatsby-plugin-react-helmet: 3.1.2 => 3.1.2 gatsby-plugin-remote-images: 1.0.3 => 1.0.3 gatsby-plugin-robots-txt: 1.5.0 => 1.5.0 gatsby-plugin-sentry: 1.0.1 => 1.0.1 gatsby-plugin-sharp: 2.2.7 => 2.2.7 gatsby-plugin-sitemap: 2.2.3 => 2.2.3 gatsby-plugin-styled-components: 3.1.2 => 3.1.2 gatsby-source-airtable: 2.0.8 => 2.0.8 gatsby-source-filesystem: 2.0.39 => 2.0.39 gatsby-source-prismic: ^3.0.0-beta.4 => 3.0.0-beta.7 gatsby-transformer-json: 2.2.2 => 2.2.2 gatsby-transformer-sharp: 2.2.3 => 2.2.3 npmGlobalPackages: gatsby-cli: 2.7.28

I already removed the node_modules folder, re-installed all packages (under the newest Node version) and checked my hosts file which is: 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost

devrchancay commented 5 years ago

Hi, maybe this issue #11666 can help you

mduecker commented 5 years ago

Hi, maybe this issue #11666 can help you

Thank you. Unfortunately it doesn't solve my problem. I already checked my hosts file and also the gatsby develop command works initially until I change something. So it can't be a general networking/host error.

devrchancay commented 5 years ago

That's very weird, I don't know if I already try npx gatsby clean I see that it has already deleted up to the node_modules folder.

mduecker commented 5 years ago

After some extensive research, I now found the cause:

I tried running the project inside a docker container to see if it's a problem with my local setup. Inside the container with gatsby develop the hot reloading was super slow and then also crashed from time to time, but this time with the error:

EMFILE: too many open files "file descriptors"

I checked the open file descriptors using the lsof command and saw that it spiked during hot reload and included many files in /src/reusecore/node_modules where I have imported additional components into my project.

Removing the useless node_modules folder there solved all of my problems.

fzembow commented 5 years ago

If you do need a nested folder with lots of files in it (for example, a nested project), you might also just want to increase your max file descriptor limit (eg on OSX ulimit -n should be higher than 256). See https://superuser.com/a/1171023 on how to do that.

Ideally gatsby's file watching can be told to ignore subdirectories but I haven't found a way to do that yet.