'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
Been happening to me too. I'm using CRAL with graphql-yoga, any updates?
+1 - I've had the same issue
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
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.
yes, I'm getting this repeatedly, every edit almost
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.
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.
Also seeing this all the time, both on build and on file changes. We invested quite a bit of time into refactoring our frontend to run completely on netlify dev so this is really frustrating! We are running an Ember.js app with a bunch of netlify functions
One thing we have noticed is that using Chrome in particular triggers this error where other browsers don't seem to...
I'm actually getting the error almost constantly using Firefox, so its not just a Chrome issue. I can't seem to narrow down the cause.
May I ask why this hasn't been given attention since August?
@raeesbhatti @sw-yx
This is high on my priority list but I haven't able to reproduce it because it is not consistent. It would be greatly helpful if you can share any of your repos that have this issue more often. I've tried this on macOS, is it more common on other OS'es? Also, in the meantime, we pushed a change recently that cleans up the CRA-like server processes when the Netlify Dev crashes. Please provide feedback on that issue here: https://github.com/netlify/cli/issues/580
@raeesbhatti For what it's worth, I was getting it consistently and frequently in Jekyll projects on MacOS, even when it was freshly generated. I haven't used it in a few months, but I can try and reproduce again. Did not seem to be browser specific in my experience.
@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.
- 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 uperrors) a.npm install -g ionicb.ionic startc. Provide a name, selectreact, selectsidemenud.cdinto the newly created directory - Run
netlify dev, then immediately go do weird things with localhost:8888 in the browser. What I mean by that: a. Runnetlify 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, runnetlify 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 devopens 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!
@raeesbhatti I have the problem in Windows, so with @dustb0wl 's input, it seems to be cross-platform.
I'm running a nuxt app.
I have one of the same issues as above, from time to time -- Closing (and sometimes refreshing) the browser tab can trigger the socket hang up. But the majority of the time, for me, it happens while just sitting there between making changes to code.
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
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
Running into this issue since forever, too. It's not consistent at all. For all I know, it happens when I save a change which triggers a reload, and then do something during the reload that causes the error to throw. Might be completely wrong though, it's just my hypothesis that appears to work, i.e. avoid seeing this error more often. 😆
/Users/mrlubos/.nvm/versions/node/v12.14.1/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
throw ex;
^
Error: socket hang up
at connResetException (internal/errors.js:570:14)
at Socket.socketCloseListener (_http_client.js:380:25)
at Socket.emit (events.js:228:7)
at Socket.EventEmitter.emit (domain.js:475:20)
at TCP.<anonymous> (net.js:664:12) {
code: 'ECONNRESET'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 7
@mrlubos Saves during reload causing the error has been my experience as well.
I am launching Eleventy server eleventy --serve through netlify dev.
I noticed there are lingering BrowserSync, node watch and server processes. See if there are lingering processes
ps -Af|grep -i eleventy
501 55407 55406 0 7:36PM ?? 0:00.28 node /Users/mikkoohtamaa/code/capitalgram/node_modules/.bin/cross-env ELEVENTY_ENV=dev eleventy --serve
501 55408 55407 0 7:36PM ?? 0:06.97 node /Users/mikkoohtamaa/code/capitalgram/node_modules/.bin/eleventy --serve
501 55531 97653 0 7:40PM ttys000 0:00.00 grep -i eleventy
To get rid of them do:
pkill -f eleventy
Then I disabled BrowserSync in eleventy.js, disabled autolaunch
[dev]
command = "npm run start"
autoLaunch = false
However even this does not help, I am still getting extra background processes and the socket error
[Browsersync] Reloading Browsers...
/usr/local/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
throw ex;
^
Error: socket hang up
at createHangUpError (_http_client.js:330:15)
at Socket.socketCloseListener (_http_client.js:371:25)
at Socket.emit (events.js:194:15)
at TCP._handle.close (net.js:613:12)
I think it might be caused by some kind of race condition with file watching and autoreload, or Netlify correctly not detecting it when Eleventy process autoreloads, but this is just a hunch.
Like other commenters pointed out, one needs to restart the whole stack between each function call that causes the issue, making Netlify dev server so unpleasant to work with that it is not very useful.
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.
- In one terminal start Lambda
npx netlify-lambda serve src/functions
It will listen for API function calls in localhost:9000.
-
In another port start
npx eleventy --serve. It will listen to the page request in localhost:8080. -
In all your source files, have a switch between
prodandenvthat will write API function URLs differently depending are you running them locally or not.