- 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.
v10.15.1yarn2.12.0Been 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.
socket hang up errors)npm install -g ionicionic startreact, select sidemenucd into the newly created directorynetlify dev, then immediately go do weird things with localhost:8888 in the browser. What I mean by that:netlify dev, then as soon as browser opens localhost:8888, close the browser tab => socket hang up errornetlify dev, and spam the refresh button on the existing localhost:8888 tab (while the new localhost:8888 tab is popping up) => socket hangup errorOne 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...
netlify dev opens a new browser tab for localhost:8888 every time...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.
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 prod and env that will write API function URLs differently depending are you running them locally or not.
I tried using netlify-lambda and although this definitely does not crash as often and when it does I don't need to recompile my entire react project every time. However, there are a lot more items you need to reconfigure.
I really just want to develop without netlify crashing every single time I reload my browser. Are there any progress on what to do?
Any updates on resolving this?
EDIT: tested this on Node 12, and it seems to only happen on Node 13 on startup - however it still happens when invoking a Netlify function.
There's some chance this is a different problem, but I was running into similar issues.
/project/node_modules/netlify-redirector/lib/redirects.js:116
throw ex;
^
Error [ERR_STREAM_WRITE_AFTER_END]: write after end
at write_ (_http_outgoing.js:594:17)
at ServerResponse.write (_http_outgoing.js:586:15)
at /project/node_modules/netlify-cli/src/utils/serve-functions.js:163:18
at /project/functions/volunteer.js:34:9
at /project/node_modules/googleapis-common/build/src/apirequest.js:43:53
at processTicksAndRejections (internal/process/task_queues.js:93:5)
Emitted 'error' event on ServerResponse instance at:
at writeAfterEndNT (_http_outgoing.js:649:7)
at processTicksAndRejections (internal/process/task_queues.js:81:21) {
code: 'ERR_STREAM_WRITE_AFTER_END'
}
and
⢀ Building development bundle/project/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:215:7)
at TCP.<anonymous> (net.js:659:12) {
code: 'ECONNRESET'
}
The latter seemed to occur when I was too quick to refresh the function invocation after restarting netlify dev.
The error, in the end, looks like being that I was calling a callback function from an async handler. The line https://github.com/netlify/cli/blob/aea57cb0d06b7341cd72f4aaa361cefbc370be9f/src/utils/serve-functions.js#L122 is what tipped me off to the issue.
For anyone watching this, it's now top priority 👍 Updates soon.
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
Also getting this error frequently. Using https://github.com/netlify-templates/gatsby-starter-netlify-cms and it often corrupts the .cache directory. Have to manually run gatsby clean and kill node processes before I can run netlify dev
We've discovered a cure-all fix for this problem. And it is in the pipeline to be released soon. Please hold on.
We've just published a new version (2.37.0). Please update and let us know if it works for you.
The fix seems to be working for me! Thanks!
Same problem, but only in deployment. It happens every now and then, and never in dev. I need to ship my app and this is a deal breaker atm. Help!
message: 'request to https://db.fauna.com/ failed, reason: socket hang up',
hello,
Same problem with faunadb request after deployment on src change
request to https://db.fauna.com/ failed, reason: socket hang up
This issue still exists.
GraphQL error: request to https://db.fauna.com/ failed, reason: socket hang up
@abtx @zb2oby @t2ca not sure about your case, but maybe this link can help you - https://github.com/netlify/netlify-faunadb-example/issues/15.
@abtx @zb2oby @t2ca not sure about your case, but maybe this link can help you - netlify/netlify-faunadb-example#15.
Thank you @kremenhero
I am still seeing this issue constantly and I am on netlify cli version 2.52.0. It makes netlify dev basically unusable for me. My node version is 12.18.0
Version:
netlify -v
netlify-cli/2.52.0 darwin-x64 node-v12.18.0
Error:
error while proxying request: socket hang up
/Users/user/.config/yarn/global/node_modules/netlify-redirector/lib/redirects.js:116
throw ex;
^
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21) {
errno: 'ECONNRESET',
code: 'ECONNRESET',
syscall: 'read'
}
error Command failed with exit code 7.
@RaeesBhatti seems this needs another look.
Any solution for this?
Same issue here.
Details:
OS: macOS 10.15.4
Node version: 10.21.0 (also tried with 12.8.0)
Netlify CLI: netlify-cli/2.54.0
EDIT:
I have more info about the error. It only happens (at least to me), when on fauna query I specify a queryTimeout. When I remove it works fine.
const q = require('./db/fauna').q
const client = require('./db/fauna').client
exports.handler = async (evnet, context) => {
const collections = client.query(
q.paginate(q.collections()),
{ querytimeout: 1 } // <-- This line
)
return {
statuscode: 200,
body: json.stringify(collections)
}
}
Hope it helps.
What worked for was to make sure that any ports (e.g. 8000, 8888 - or whatever your using) is not used already. On mac, check lsof -i TCP:8000 | grep LISTENand kill the blocking process kill -9 PID_TO_KILL . Try to restart your app.
Most of the replies here seem related to fauna - it seems the original fix was effective. If someone feels their issue is caused by the CLI, you can open a new issue and we can discuss there.
Still happening here... MacOS, [email protected]
Hi @lluishi93, do you mind opening a new issue with more information on your setup and when is the error being reported?
I was seeing something very similar to this, purportedly coming from something related to netlify cli:
/Users/<my name>/.nodenv/versions/14.7.0/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
throw ex;
^
RangeError [ERR_OUT_OF_RANGE]: The value of "err" is out of range. It must be a negative integer. Received 536870212
at Object.getSystemErrorName (util.js:231:11)
at exceptionWithHostPort (internal/errors.js:532:21)
at internalConnect (net.js:922:16)
at defaultTriggerAsyncIdScope (internal/async_hooks.js:429:12)
at GetAddrInfoReqWrap.emitLookup [as callback] (net.js:1062:9)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:68:8) {
code: 'ERR_OUT_OF_RANGE'
However, after a while I was able to track this issue down to being related to a mismatch between your versions of Node and NPM.
BUT, in _my case_ I hadnt recently updated either of these things (and use .node-version, .nvmrc, and package.json files to keep these things in order) so it was confusing why this would suddenly happen... then I remembered I had recently stopped my Little Snitch/LuLu process from allowing an outgoing request from that node version... re-allowing it stopped the issue.
Most helpful comment
We've just published a new version (2.37.0). Please update and let us know if it works for you.