Skip to content

"[WDS] Disconnected" loop #1796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 2 tasks
dennispg opened this issue Apr 13, 2019 · 50 comments
Closed
1 of 2 tasks

"[WDS] Disconnected" loop #1796

dennispg opened this issue Apr 13, 2019 · 50 comments

Comments

@dennispg
Copy link
Contributor

  • Operating System: Windows 10 - 1809

  • Node Version: v8.14.0

  • NPM Version: 6.9.0

  • webpack Version: 4.30.0

  • webpack-dev-server Version: 3.3.1

  • Browser version: Chrome 73.0.3683.103 (64-bit)

  • This is a bug

  • This is a modification request

Expected Behavior

Should not repeatedly reload the page after displaying [WDS] Disconnected.

Actual Behavior

Does not strictly happen every single time, sometimes it works. But more often than not, after making a change the hot reload will go into a loop reloading the page and displaying [WDS] Disconnected over and over.

It seems like two "o" sockjs msgs can be received during the same session, possibly when changes are recompiled in succession fast enough? This causes two socket opens, and when the second open request checks the readystate it is already open from the first request and so triggers a [WDS] Disconnect.

How can we reproduce the behavior?

A reproducible repo is available here:
https://github.com/dennispg/webpack-wds-disconnected-bug

  1. run npm start, open https://localhost:9000/ in Chrome
  2. find sockjs.js in the sources panel
  3. add a breakpoint on line 933 which should look like: this._close(1006, 'Server lost session');
  4. add some random semicolons in src/index.js over and over till the breakpoint hits. Try modify/save/modify/save in rapid succession for best results.
@alexander-akait
Copy link
Member

Feel free to send a PR with fix

@dennispg
Copy link
Contributor Author

I would love do to exactly that, however I have been unable to track down a proper fix on my own. I have tried, and this was the most I was able to find out. I will continue to research, but I worry that I need assistance to go any further.

I had hoped it would be helpful to provide a reproducible test repo in order to get some assistance at least in finding a solution. If creating a reproducible test repo is a waste of time though, please do let me know.

@alexander-akait
Copy link
Member

alexander-akait commented Apr 13, 2019

I had hoped it would be helpful to provide a reproducible test repo in order to get some assistance at least in finding a solution. If creating a reproducible test repo is a waste of time though, please do let me know.

No, reproducible test repo allow to us fix problem very fast, i written Feel free to send a PR with fix because now it is weekends and you maybe want fix this asap so you can send a PR. We will fix this anyway.

@dennispg
Copy link
Contributor Author

I completely understand, there is no rush for a fix. I just want to help find the solution, so I shared here. I will continue to research also.

@funwithtriangles
Copy link

I rolled back to webpack-dev-server 3.0.0 and webpack 4.20.2 and still experiencing this issue. I'm on Windows 10 (1803).

I'm wondering if it has something to do with having https enabled. I don't seem to be experiencing it once I set this option to false but this might also be due to the fact my page doesn't get as far without it.

Seems related: #851

@alexander-akait
Copy link
Member

@funwithtriangles can you create minimum reproducible test repo, maybe you have other problem, thanks

@blackswanny
Copy link

blackswanny commented Apr 16, 2019

have the same issue since updated from 2.x to 3.2 version with the update of webpack to 4.28.4

previously worked config for devServer:

{
      https: true,
      cert: options.https.cert,
      key: options.https.key
}

since in here https://webpack.js.org/configuration/dev-server/
I see the change to nest cert and key inside of https object, so the next config doesn't work as well:

{
      https: {
        cert: options.https.cert,
        key: options.https.key
      }
 }

this hammer also doesn't work:

     {
      headers:          { 'Access-Control-Allow-Origin': '*' },
      disableHostCheck: true,
      https: false
    }

here there is ca prop for https, what is this one? Do I need it also?
https://webpack.js.org/configuration/dev-server/

image

@alexander-akait
Copy link
Member

 https: {
   ca: 'something',
   cert: options.https.cert,
   key: options.https.key
}

https://github.com/webpack/webpack-dev-server/blob/master/lib/utils/createConfig.js#L155

@blackswanny
Copy link

ok, thanks. I can find in code, just didn't get what it means. Seems it stands for specific cacert certificates. However it makes no difference. I rolled back to [email protected], [email protected] and the issue is still there. My chrome is 73.0.3683.103 and Firefox 66.0.3 . Chrome is still complaining and I have infinite loop of requests, which makes impossible to use dev tools as it is stuck processing those requests. However, Firefox stopped issue with old 2.11.5 version of webpack-dev-server. So it might be a mix of newly released Chrome and new version of sockjs or [email protected]. Any ideas?

@alexander-akait
Copy link
Member

@blackswanny can you create minimum reproducible test repo with 3 version, webpack-dev-server@2 is deprecated and can doesn't work

@elesueur
Copy link

elesueur commented May 6, 2019

@evilebottnawi I have this issue too, with SSL mode, in webpack-dev-server 3.3.1. It seems to have come along with Chrome 74. I don't think anything else in my environment changed. I see a failure in the first websocket connection (only for certain routes within my app! and the app reloads continuously). The websocket fails to connect with a timeout (error code 1006).

I applied the fix suggested in #851 (comment) to webpack-dev-server, and everything works fine.

I can send a merge request if desired. Unfortunately, I do not have a minimum reproduction.

FYI, I have my dev server running on a non-standard port with Angular CLI (port 4300 instead of port 4200, though this doesn't seem to make a difference), I have SSL enabled with a fully trusted self-signed cert, with a subject alternative name (which Chrome apparently desires now) and it is marked as fully trusted in Keychain Access app. I do not get any warnings when Chrome first loads the site. I have disableHostCheck set and my app runs on localhost.somedomain.com, which is set in my /etc/hosts file to 127.0.0.1.

@ZebraFlesh
Copy link

I'm seeing this consistently on both Mac and Windows 10 using Chrome 74, Safari 12.1.1, and Firefox 67. I was able to narrow things down a little: I was upgrading some stale dependencies and saw this error occur, so I restarted the dependency upgrades and was very methodical. This occurred when I jumped from webpack-dev-server 3.2.1 to 3.3.0 (with the corresponding required upgrade of webpack-cli from 3.2.3 to 3.3.2). I'm also extremely far from a minimum reproduction scenario.

My solution for now is to stick with webpack-dev-server 3.2.1 / webpack-cli 3.2.3.

@alexander-akait
Copy link
Member

Don't stick version, it can be broken in future, please create minimum reproducible test repo

@jsg2021
Copy link

jsg2021 commented May 28, 2019

If your dev server is behind a proxy, it might be sending requests to the wrong place. I was having a similar issue and solved it with defining public to be localhost:devserverport

@alexander-akait
Copy link
Member

/cc @elesueur sorry for delay, we need this fix, can you send a PR?

@blackswanny
Copy link

fyi, I have it with Chrome( latest 74.x version), but I don't have it with Chrome Canary ( 76.x version). So may be something is with my code, but it is fixed in 76.x version of Chrome. Also Firefox and Safari seems to not reproduce it

@ZebraFlesh
Copy link

I see this consistently with both the release and canary channels of Chrome on Windows 10.

@alexander-akait
Copy link
Member

@ZebraFlesh what do you mean?

@ZebraFlesh
Copy link

I'm saying it's not resolved by Chrome 76 as @blackswanny suggests

@alexander-akait
Copy link
Member

@ZebraFlesh Can you create minimum reproducible test repo?

@ZebraFlesh
Copy link

ZebraFlesh commented May 29, 2019

Not easily, no. I've got a privately forked version of this repo: https://github.com/arabold/serverless-react-boilerplate/. It's using serverless framework with the serverless-offline plugin to exec a webpack-dev-server process. I'm not even sure where to begin on unraveling all that into something minimal. My suspicion is that offline environment is doing something that is unexpected by WDS, so "minimal" might still be "quite complicated".

@alexander-akait
Copy link
Member

@ZebraFlesh bad, with reproducible test repo we will fix it very fast

@dennispg
Copy link
Contributor Author

Just in case it was missed.. there has been a minimum reproducible repo available in the OP all this time.

@ZebraFlesh
Copy link

@ZebraFlesh bad, with reproducible test repo we will fix it very fast

I understand that. If I thought I could provide a minimal repo I would have already done so. But like I said, my failure case is quite far from minimal. If you think it would help, I’m happy to try and work it up.

@alexander-akait
Copy link
Member

@ZebraFlesh can you send not minimal version? Sometimes impossible create minimum reproducible test repo

@ZebraFlesh
Copy link

This branch demonstrates the problem: https://github.com/ZebraFlesh/serverless-react-boilerplate/tree/wds-broken The last commit on that branch causes the issue we've been talking about (by upgrading to latest WDS); reset head to previous commit to get a working version.

To execute:

  1. Make sure you have some AWS credentials set in your environment. This won't work without credentials.
    1. If unfamiliar, fastest thing is to set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in your current shell environment.
    2. To obtain free credentials, see this stack overflow answer
  2. Execute npm start
  3. Visit http://localhost:300
  4. Watch both the serverless offline output in your console and the browser console output go crazy with looping

@alexander-akait
Copy link
Member

@ZebraFlesh thanks

@dennispg
Copy link
Contributor Author

@ZebraFlesh out of curiosity, does the repo in the OP also have the same problem in your environment?
https://github.com/dennispg/webpack-wds-disconnected-bug

@ZebraFlesh
Copy link

@dennispg No, I couldn't make it break using the repo in the OP. I tried on macOS 10.14.5 with node 10.15.3 and Chrome 74.

@funwithtriangles
Copy link

Just for extra information, I stopped getting this issue but now I'm testing on iOS Safari and it is happening every time.

@alexander-akait
Copy link
Member

Only on Safari?

@funwithtriangles
Copy link

funwithtriangles commented May 30, 2019

Just tested in Chrome on iOS, same thing happening there. On Android it's fine. 🙁

@alexander-akait
Copy link
Member

Only iOS? Sorry for many questions

@funwithtriangles
Copy link

Chrome on Android: ✔️
Chrome on iOS: ❌
Safari on iOS: ❌

@funwithtriangles
Copy link

So I have some sort of solution to this problem, which actually seems to be two problems for iOS. Firstly, there was an issue of the page refreshing really fast (#1370). This doesn't seem to be related to WDS but I managed to get past this issue following this advice: #1370 (comment)

However this lead me back to the WDS loop issue, which I seem to have solved by setting inline: false.

@blackswanny
Copy link

seems to be related
#1616

@puru991
Copy link

puru991 commented Jul 3, 2020

If on a vps, Just do a yarn serve --public [your-public-ip-address], for eg. yarn serve --public 83.12.33.24
If on local, try setting public to either localhost or 127.0.0.1 (Although did not try on local)

@sajidmansoori12
Copy link

Don't know how...but when I add the property injectClient:false to the devServer. The WDS disconnected stops showing up.

@nefarioustim
Copy link

This can generally be fixed by defining public. For some reason, WDS can't find the right address without it:

devServer: {
    https: true,
    port: 8080,
    public: "0.0.0.0:8080"
}

@StevenBarquet
Copy link

StevenBarquet commented May 29, 2021

This can generally be fixed by defining public. For some reason, WDS can't find the right address without it:

devServer: {
    https: true,
    port: 8080,
    public: "0.0.0.0:8080"
}

Thanks I modified my config to this and it works:

devServer: { port: 3000, public: 'localhost:3000', }

@alexander-akait
Copy link
Member

We refactor our code and in the next version you will have client.webSocketURL so you can setup right hostname/port/etc for proxyed dev server, also [WDS] Disconnected very often means you have invalid publicPath in webpack v5 we use auto (all assets are relative) by default, so it should happens very rare

@erikmartinessanches
Copy link

erikmartinessanches commented Jul 23, 2021

I'm getting this error in Chrome version 92.0.4515.107 and webpack-dev-server 3.11.1 created by npx create-react-app on http://localhost:3000/. Link to repository.
image

@alexander-akait
Copy link
Member

it means you have invalid URL for sockjs, what is in your address bar in browser

@erikmartinessanches
Copy link

it means you have invalid URL for sockjs, what is in your address bar in browser

http://localhost:3000/

@alexander-akait
Copy link
Member

alexander-akait commented Jul 23, 2021

But for web socket connection your are use 9090, so you got this problem, why do you use 3000 port? Your URL in address bar should be http://localhost:9090

@erikmartinessanches
Copy link

But for web socket connection your are use 9090, so you got this problem, why do you use 3000 port? Your URL in address bar should be http://localhost:9090

Thanks but I use port 3000 because of this:
image

If I use port 9090 I get "Unable to reach page" and only a crbug/1173575, non-JS module files deprecated.in the console.

@alexander-akait
Copy link
Member

Something buggy in CRA... Sorry, I am afraid we can't fix it here, web socket address should be same as in address bar in browser, if you need proxy, you need more options for dev server, also please try PORT=9090 react-scripts start

@erikmartinessanches
Copy link

erikmartinessanches commented Jul 23, 2021

Something buggy in CRA... Sorry, I am afraid we can't fix it here, web socket address should be same as in address bar in browser, if you need proxy, you need more options for dev server, also please try PORT=9090 react-scripts start

Thanks, I'll open an issue with CRA. PORT=9090 react-scripts start didn't work for me, at least not in the root directory of the app. PORT=9090 yarn start did start serving on http://localhost:9090, but with the same error.

@alexander-akait
Copy link
Member

weird, your repo works fine for me, check your env variables, run printenv if you on linux and check you don't have port variable or try to PORT=3000 react-scripts start

@erikmartinessanches
Copy link

erikmartinessanches commented Jul 23, 2021

No port variable visible when printenv. Tried PORT=3000 yarn start which also runs react-scripts, as I understand it. Interestingly, now the error is about port 9090: sockjs.js?9be2:1605 GET http://localhost:9090/sockjs-node/info?t=1627076185160 net::ERR_CONNECTION_REFUSED.

Tried with port 9090 and got this warning and a bunch of 404s:

WebSocket connection to 'ws://localhost:9090/sockjs-node/909/s0o2cyhv/websocket' failed: WebSocket is closed before the connection is established.

sockjs.js?9be2:1605 POST http://localhost:9090/sockjs-node/909/zorulcwl/xhr_streaming?t=1627076597133 404 (Not Found)
AbstractXHRObject._start @ sockjs.js?9be2:1605
eval @ sockjs.js?9be2:1494
setTimeout (async)
AbstractXHRObject @ sockjs.js?9be2:1493
XHRCorsObject @ sockjs.js?9be2:2871
XhrReceiver @ sockjs.js?9be2:2596
Polling._scheduleReceiver @ sockjs.js?9be2:2143
Polling @ sockjs.js?9be2:2135
SenderReceiver @ sockjs.js?9be2:2199
AjaxBasedTransport @ sockjs.js?9be2:1977
XhrStreamingTransport @ sockjs.js?9be2:3139
SockJS._connect @ sockjs.js?9be2:828
SockJS._transportClose @ sockjs.js?9be2:912
SockJS._transportTimeout @ sockjs.js?9be2:846
setTimeout (async)
SockJS._connect @ sockjs.js?9be2:822
SockJS._receiveInfo @ sockjs.js?9be2:802
g @ sockjs.js?9be2:66
EventEmitter.emit @ sockjs.js?9be2:86
eval @ sockjs.js?9be2:567
g @ sockjs.js?9be2:66
EventEmitter.emit @ sockjs.js?9be2:86
eval @ sockjs.js?9be2:374
g @ sockjs.js?9be2:66
EventEmitter.emit @ sockjs.js?9be2:86
xhr.onreadystatechange @ sockjs.js?9be2:1597
XMLHttpRequest.send (async)
AbstractXHRObject._start @ sockjs.js?9be2:1605
eval @ sockjs.js?9be2:1494
setTimeout (async)
AbstractXHRObject @ sockjs.js?9be2:1493
XHRCorsObject @ sockjs.js?9be2:2871
InfoAjax @ sockjs.js?9be2:356
InfoReceiver._getReceiver @ sockjs.js?9be2:539
InfoReceiver.doXhr @ sockjs.js?9be2:556
eval @ sockjs.js?9be2:525
setTimeout (async)
InfoReceiver @ sockjs.js?9be2:524
SockJS @ sockjs.js?9be2:730
initSocket @ socket.js?e29c:9
eval @ client?3a70:231
eval @ index.js?http://localhost:9090:271
./node_modules/webpack-dev-server/client/index.js?http://localhost:9090 @ sidebar.bundle.js:22027
__webpack_require__ @ sidebar.bundle.js:790
fn @ sidebar.bundle.js:101
1 @ sidebar.bundle.js:22878
__webpack_require__ @ sidebar.bundle.js:790
(anonymous) @ sidebar.bundle.js:857
(anonymous) @ sidebar.bundle.js:860
eventsource:1 

I opened an issue on CRA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests