webpack-dev-server icon indicating copy to clipboard operation
webpack-dev-server copied to clipboard

spdy break content when you use difference protocols for dev server and proxy

Open jrweinb opened this issue 6 years ago • 47 comments

  • Operating System: MacOS High Sierra v 10.13.6
  • Node Version: 8.9.2
  • NPM Version: 6.4.1
  • webpack Version: 4.26.0
  • webpack-dev-server Version: 3.1.10
  • [x] This is a bug
  • [ ] This is a modification request

Code

  // webpack.config.js

config.devServer = {
    hot: true,
    contentBase: resolve(__dirname, '/'),
    disableHostCheck: true,
    publicPath: '/',
    headers: {
        'Accept-Encoding': '',
    },
    historyApiFallback: true,
    host: '0.0.0.0',
    compress: true,
    quiet: true,
    proxy: {
        '/api': {
            target: 'https://XXXXX',
            secure: false,
            changeOrigin: true,
        }
}

I added the Accept-Encoding header per this advice: https://github.com/webpack/webpack-dev-server/issues/354, but it does not solve the problem. I also tried changing the timeout settings without success

Expected Behavior

That when proxying a GET request to /api, the full JSON response will be received

Actual Behavior

Sometimes the request is properly fulfilled and sometimes the response is truncated. This only happens with > 3mb JSON response.

When disabling Chrome web security and making the request directly to the server (without the wds proxy), the request is always fulfilled properly.

For Bugs; How can we reproduce the behavior?

Make a GET request with a JSON response > 3mb through the wds proxy.

To test without the proxy, disable Chrome security and make the request directly to the server.

To disable web security, from terminal:

open /Applications/Google\ Chrome.app --args --user-data-dir="/var/tmp/Chrome dev session" --disable-web-security

jrweinb avatar Nov 20 '18 16:11 jrweinb

@jrweinb can you create minimum reproducible test repo?

alexander-akait avatar Nov 20 '18 17:11 alexander-akait

@evilebottnawi - I was unable to reproduce the error when serving a large file from a local node server. I apologize, but I failed to mention in my bug report that I am on a corporate VPN...I believe that this is the source of the issue. I found a relevant issue in the http-proxy-middleware repo: https://github.com/chimurai/http-proxy-middleware/issues/171 However, adding a "Connection": "keep-alive" header does not solve the problem for me. The only solution is to run Chrome with web security disabled

jrweinb avatar Nov 21 '18 15:11 jrweinb

I also got this issue after upgrading from 3.1.10. Big JSON responses get either truncated or even corrupted.

mehl321 avatar Jan 09 '19 17:01 mehl321

@mehl321 maybe you can create minimum reproducible test repo?

alexander-akait avatar Jan 09 '19 17:01 alexander-akait

I created a minimal repo on my machine with a similar config (proxy, HMR, fetching a similar JSON from another local server. No HTTPS though) but I couldn't reproduce the bug. There is a bug for sure because downgrading to 3.1.10 fixed the issue.

mehl321 avatar Jan 11 '19 21:01 mehl321

@mehl321 so we can close issue?

alexander-akait avatar Jan 14 '19 11:01 alexander-akait

Close the issue if you want but I think the bug is still here. I just didn't manage to reproduce it.

mehl321 avatar Jan 14 '19 13:01 mehl321

/cc @jrweinb friendly ping

alexander-akait avatar Jan 14 '19 13:01 alexander-akait

I'm encountering this too but couldn't make minimum reproducible test repository.

3.1.9 OK 3.1.10+ truncates/corrupts proxied https JSON responses

Operating System: Windows 10 Node Version: 8.12.0 NPM Version: 6.4.1 webpack Version: 4.29.0 webpack-dev-server Version: 3.1.10 - 3.1.14

hkostia avatar Jan 31 '19 05:01 hkostia

I think problem on proxy server side, we don't touch content from proxy

alexander-akait avatar Jan 31 '19 09:01 alexander-akait

+1 on this issue. downgrade to 3.1.9 worked for me. I have no reproducible test/repo for you.

emillynge avatar Feb 15 '19 10:02 emillynge

@eemeli we don't touch anything with 3.1.9 around proxy

alexander-akait avatar Feb 15 '19 10:02 alexander-akait

@evilebottnawi Well, it was literally the only change in my setup. Maybe a dependency changed? in which case it would be helpful to track down which dep could cause this.

emillynge avatar Feb 15 '19 14:02 emillynge

@emillynge yep, so we need reproducible test repo, it is help to solve this issue

alexander-akait avatar Feb 15 '19 14:02 alexander-akait

My Payload is 512KB and I have the same issue. JSON it gets corrupts in webpack-dev-server Version: 3.1.11 - 3.1.14. The only one is working fine is 3.1.10

victors1681 avatar Feb 15 '19 20:02 victors1681

@victors1681 please create minimum reproducible test repo, otherwise issue was closed and marked as spam

alexander-akait avatar Feb 15 '19 20:02 alexander-akait

I meet some issue in version 3.1.14, my payload is 27.5KB, enabled https proxy. After I downgrade to 3.1.10, it works fine also. I think the issue should happened in proxy side, please help to check and fixed. Thanks

edwint229 avatar Feb 19 '19 11:02 edwint229

@edwint229 Can you provide minimum reproducible test repo?

alexander-akait avatar Feb 19 '19 11:02 alexander-akait

i found our api response data (large json ) is truncated . the api server support http2 and it only reproduced in http2 . we can force proxy server use http1.1 always:

https: {
key: ...
cert: ...
spdy: {
   protocols: ['http1.1']
 }
}

// waiting for  'http2'  module stable, and express support

houfeng0923 avatar Feb 26 '19 13:02 houfeng0923

@houfeng0923 Can you create minimum reproducible test repo?

alexander-akait avatar Feb 26 '19 14:02 alexander-akait

I'm having the same issue with webpack-dev-server 3.2.1 The JSON response is truncated. Downgrading to 3.1.10 solves the issue. Could someone take a look at this, please?

dnicoara-psft avatar Feb 28 '19 10:02 dnicoara-psft

@evilebottnawi , i guess a http2 bug in node-spdy or http-proxy-middleware . webpack-dev-server depend on express , express use node-spdy to support http2 feature .

i ceate a spdy-http2/node-spdy#357 here.

houfeng0923 avatar Mar 04 '19 02:03 houfeng0923

@houfeng0923 thanks for investigateion

alexander-akait avatar Mar 04 '19 08:03 alexander-akait

same issue here with Node v8 update to Node v10 solve my problem

lzane avatar Mar 06 '19 08:03 lzane

node v10 forces webpack-dev-server to use https server instead of spdy, I think just an option to select manually would be a solution in that particular case

yadue avatar Mar 06 '19 08:03 yadue

@yadue why?

alexander-akait avatar Mar 06 '19 09:03 alexander-akait

for users who are not using nodejs 10 for some reasons it uses only spdy which in webpack-dev-server above 3.1.10 fails for some reasons for the guys here, it truncates response in some cases. there is no way for us to use latest versions of webpack-dev-server since we can't manually select which protocol we want to use

webpack-dev-server detects node v10 and runs https server which works just fine, node < 10, runs spdy library which above version 3.4.7 fails for some users

yadue avatar Mar 06 '19 09:03 yadue

@yadue it is not solution, we should find problem and fix it, no need implement hacks

alexander-akait avatar Mar 06 '19 09:03 alexander-akait

What is problem create minimum reproducible test repo?

alexander-akait avatar Mar 06 '19 09:03 alexander-akait

here you go: https://github.com/yadue/webpack-dev-server-proxy-issue npm install npm run start open https://app.localhost:4201/ you'll see 2 requests proxied to http://yadue.synology.me/api3/2jcegul7ephjg2emsfg4v5097g.json (10kb) http://yadue.synology.me/api3/2jcegul7ephjg2emsfg4v5097g-small.json (2kb) https://imgur.com/a/sXfyiuY

it really took me so long to find reproducible case.

yadue avatar Mar 06 '19 10:03 yadue