cli: 'socket hang up' error thrown randomly

- Do you want to request a feature or report a bug?

Bug

- What is the current behavior?

At points during development the following error occurs which stops the entire Netlify Dev stack:

.../node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^

Error: socket hang up
    at createHangUpError (_http_client.js:323:15)
    at Socket.socketCloseListener (_http_client.js:364:25)
    at Socket.emit (events.js:194:15)
    at TCP._handle.close (net.js:600:12)

Looks like it was also reported on the community forum back in April - https://community.netlify.com/t/netlify-dev-regularly-crashes/551

- If the current behavior is a bug, please provide the steps to reproduce.

I haven’t been able see any common pattern for what causes this.

- What is the expected behavior?

Should not crash.

- Please mention your node.js, and operating system version.

  • Node: v10.15.1
  • Using yarn
  • Netlify CLI 2.12.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 47
  • Comments: 57 (12 by maintainers)

Commits related to this issue

Most upvoted comments

We’ve just published a new version (2.37.0). Please update and let us know if it works for you.

For anyone watching this, it’s now top priority 👍 Updates soon.

Adding onto what @pushred mentioned above; it’d be great if the port could also be shut-down in the event an error is caught - re-googling sudo lsof -i tcp:3000 and kill -QUIT <PID> is sadly something I will never memorize and is the bane of my existence.

Yah, I’m getting this as well. For anyone on mac, if you don’t have any other node processes running, killall node saves me from having to use lsof. Use it with caution though obviously.

The issue seems like an unhandled error isn’t been returned properly somewhere, but I haven’t been able to specifically isolate when it happens.

For me this occurs when I change a function:

◈ functions/guests/guests.js modified, reloading...
/Users/example/.nvm/versions/node/v10.15.3/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^

Error: socket hang up
    at createHangUpError (_http_client.js:323:15)
    at Socket.socketCloseListener (_http_client.js:364:25)
    at Socket.emit (events.js:194:15)
    at TCP._handle.close (net.js:597:12)

…or a CRA src file:

Compiling...
Compiled successfully!
/Users/example/.nvm/versions/node/v10.15.3/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^

Error: socket hang up
    at createHangUpError (_http_client.js:323:15)
    at Socket.socketCloseListener (_http_client.js:364:25)
    at Socket.emit (events.js:194:15)
    at TCP._handle.close (net.js:597:12)

Version: netlify-cli/2.13.0 darwin-x64 node-v10.15.3

It’s also worth noting that with CRA at least it’s processes remain running after the crash and must be killed before netlify dev can start again.

99970 ttys000    0:00.14 /Users/example/.nvm/versions/node/v10.15.3/bin/node /Users/example/dev/node_modules/.bin/react-scripts start
99971 ttys000    0:12.25 /Users/example/.nvm/versions/node/v10.15.3/bin/node /Users/example/dev/node_modules/react-scripts/scripts/start.js

until this is fixed it seems that Netlify Dev is unusable for me. i am having the same issue, either in the browser or postman i can call a function one time then the server dies with this same message .

heres an example function endpoint :

localhost:8888/.netlify/functions/login

im using macos

We’ve discovered a cure-all fix for this problem. And it is in the pipeline to be released soon. Please hold on.

I’m experimenting the same crash on macOS (netlify-cli/2.30.0 darwin-x64 node-v12.10.0), running a react app.

Note that if you’re like me and find that Netlify Dev opening a new browser tab every time it restarts is annoying (and thus closing the tab immediately, causing Netlify Dev to crash), you can set the autoLaunch param to false in your netlify.toml file’s [dev] block to prevent this behavior.

[dev]
  autoLaunch = false

this thread in Community should also be updated when we have a fix. Thanks @erquhart .

https://community.netlify.com/t/error-socket-hang-up-is-there-a-cure-for-random-socket-errors/9586/2

@raeesbhatti So far, I figured out a reliable way to recreate socket hang up errors only on the initial run of netlify dev, but I’m hoping this offers us some breadcrumbs.

  1. Set up a new Ionic React project https://ionicframework.com/docs/react/your-first-app (this probably isn’t unique to Ionic or React, but it’s what my project is based on, and what I used to reproduce socket hang up errors) a. npm install -g ionic b. ionic start c. Provide a name, select react, select sidemenu d. cd into the newly created directory
  2. Run netlify dev, then immediately go do weird things with localhost:8888 in the browser. What I mean by that: a. Run netlify dev, then as soon as browser opens localhost:8888, close the browser tab => socket hang up error b. OR have localhost:8888 already open in another tab, run netlify dev, and spam the refresh button on the existing localhost:8888 tab (while the new localhost:8888 tab is popping up) => socket hangup error

One thing I have noticed before is that once I get a socket hangup error, I seem to get a bunch of them in a row (where I’m unable to run netlify dev for like 5-10 min straight). This makes me wonder…

  • since netlify dev opens a new browser tab for localhost:8888 every time
  • and my browser is autorefreshing existing, old tabs for localhost:8888

…if I don’t close the old tabs, am I essentially experiencing the behavior outlined in (2b) above?

And if so, is something similar happening if I have multiple browser tabs opened for localhost:8888?

…the mystery continues!

This has been happening to me as well. It looks like netlify-redirector isn’t open source, so it isn’t even possible to try to debug the root of the issue.

yes, I’m getting this repeatedly, every edit almost

Hi! We’ve released version 3.4.2 just now, which should fix this problem. In case someone is still experiencing it after upgrading, please reopen the issue.

Thanks! 🙌🏻

@abtx @zb2oby @t2ca not sure about your case, but maybe this link can help you - https://github.com/netlify/netlify-faunadb-example/issues/15.

The fix seems to be working for me! Thanks!

Sure 😃

hello, Same problem with faunadb request after deployment on src change request to https://db.fauna.com/ failed, reason: socket hang up

Looks like the culrpint to the pain is Netlify dev server and its proxy. You can go ahead without the proxy. Here is my workaround.

Use netlify-lambda instead of Netlify dev server.

  1. In one terminal start Lambda

npx netlify-lambda serve src/functions

It will listen for API function calls in localhost:9000.

  1. In another port start npx eleventy --serve. It will listen to the page request in localhost:8080.

  2. In all your source files, have a switch between prod and env that will write API function URLs differently depending are you running them locally or not.