question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

chrome throw ERR_HTTP2_PROTOCOL_ERROR

See original GitHub issue

Describe the bug

When I run vite devServer, Chrome occasionally fails to load some js files. The error message is net::ERR_HTTP2_PROTOCOL_ERROR. Then I re-run vite devServer and reload it, and it runs fine. But when I copied the url and opened it in a new tab, it broke again. This error only occurs in Chrome, FireFox is working fine.

image

I find some net log in chrome://net-internals/#events:

image

This is the gist of the error: HTTP2_STREAM_ERROR –> description = “Server reset stream.” –> net_error = “ERR_HTTP2_PROTOCOL_ERROR” –> stream_id = 13571

Reproduction

export const getViteConfig = (): InlineConfig => {
  const packages = [];

  return {
    configFile: false,
    mode: 'development',
    publicDir: path.resolve(process.cwd(), '.temp/vite-static'),
    css: {
      preprocessorOptions: {
        less: {
          javascriptEnabled: true,
        },
      },
    },
    define: {
      'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
      __BUILDING_TOOL__: JSON.stringify('vite'),
      __DEV__: true,
      __DEBUG_INFO__: JSON.stringify(process.env.DEBUG_INFO || ''),
      __PRIVATE__: JSON.stringify(process.env.PRIVATE),
      __PRIVATE_VERSION__: JSON.stringify(process.env.PRIVATE_VERSION || ''),
    },
    resolve: {
      alias: packages.reduce(
        (prev, curr) => ({
          ...prev,
          [curr.packageJson?.name]: path.resolve(rootPath, curr.rootPath, 'src'),
        }),
        {
          '~antd/dist/antd.less': path.resolve(rootPath, 'node_modules/antd/dist/antd.less'),
          '~antd/lib/message/style/index.css': path.resolve(rootPath, 'node_modules/antd/lib/message/style/index.css'),
        },
      ),
      mainFields: ['main', 'module', 'jsnext:main', 'jsnext'],
      extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'],
    },
    server: {
      https: true,
      port: 5001,
      hmr: {
        host: '127.0.0.1',
      },
    },
  };
};

// ...
const server = await createServer(getViteConfig());
await server.listen();

System Info

System:
    OS: macOS 10.15.6
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 21.06 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 14.17.1 - ~/.nvm/versions/node/v14.17.1/bin/node
    Yarn: 1.22.10 - ~/.nvm/versions/node/v14.17.1/bin/yarn
    npm: 7.19.1 - ~/.nvm/versions/node/v14.17.1/bin/npm
  Browsers:
    Chrome: 92.0.4515.107
    Firefox: 90.0.2
    Safari: 13.1.2
  npmPackages:
    vite: ^2.4.3 => 2.4.3

Used Package Manager

yarn

Logs

No response

Validations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:14
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ec965commented, Sep 17, 2021

I resolved this by disabling http/2 in the dev server. https://vitejs.dev/config/#server-https

Enable TLS + HTTP/2. Note this downgrades to TLS only when the server.proxy option is also used.

In vite.config.js:

  },
  server: {
    host: true,
    proxy: {
      'https://localhost:3000': 'https://localhost:3000'
    },
    https: true,
    port: 3000
  }
});

There may be an error between how chrome handles http/2 and how node.js has http/2 implemented. https://bugs.chromium.org/p/chromium/issues/detail?id=1045328#c68

Chrome sets the fin bit of the final non-empty data packet to true, which apparently triggers a bug in the server. Other browsers instead send a separate empty data packet with the fin bit set to true at the end of the request body. Both are completely valid under the HTTP/2 spec.

2reactions
prestonpcommented, Sep 13, 2021

We were able to resolve this following https://github.com/vitejs/vite/pull/3895 and adding maxSessionMemory: 100 to server.https in the vite config

Read more comments on GitHub >

github_iconTop Results From Across the Web

What's the net::ERR_HTTP2_PROTOCOL_ERROR about?
The issue is that when there's no disk space left on the disk, some webservers (nginx definitely but maybe apache as well) are...
Read more >
What is ERR_HTTP2_PROTOCOL_ERROR? How to Fix it?
HTTP2 protocol error might occur on a client device mainly due to browser issues or interference from the network.
Read more >
How to Fix ERR_HTTP2_PROTOCOL_ERROR in Chrome
1. Open Google Chrome. Click the ellipsis at the top-right corner, select More tools and click Extensions. ... 2. Toggle the slider to...
Read more >
Err_http2_protocol_error? Please help, all browsers including ...
I've tried to research and find fixes such as command prompt actions and redownloading Internet drivers but nothing has worked. Other people in ......
Read more >
How to Fix ERR_SSL_PROTOCOL_ERROR on Google Chrome
QUIC (Quick UDP Internet Connections) provides a TLS/SSL equivalent connection to Google's servers. By default, the QUIC protocol is enabled in Chrome. To ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found