Skip to content
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

server crashes on page load using custom server with compression #8408

Closed
knight-of-zero opened this issue Aug 17, 2019 · 5 comments
Closed

Comments

@knight-of-zero
Copy link
Contributor

Bug report

Describe the bug

When using a custom server (e.g. Node's native http2), the server crashes after loading the first page. Error output is:

$ npm run dev

> with-http2@1.0.0 dev /home/username/next.js/with-http2-app
> node server.js

[ ready ] compiled successfully
[ wait ]  compiling ...
Listening on HTTPS port 3000
[ ready ] compiled successfully
[ event ] build page: /
[ wait ]  compiling ...
[ ready ] compiled successfully
/home/username/next.js/with-http2-app/node_modules/compression/index.js:84
        this._implicitHeader()
             ^

TypeError: this._implicitHeader is not a function
    at Http2ServerResponse.write (/home/username/next.js/with-http2-app/node_modules/compression/index.js:84:14)
    at ReadStream.ondata (_stream_readable.js:705:22)
    at ReadStream.emit (events.js:193:13)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:276:11)
    at ReadStream.Readable.push (_stream_readable.js:231:10)
    at fs.read (internal/fs/streams.js:183:12)
    at FSReqCallback.wrapper [as oncomplete] (fs.js:478:5)

To Reproduce

  1. Run npx create-next-app --example with-http2 with-http2-app
  2. Run cd with-http2-app
  3. Copy your SSL keys into localhost-privkey.pem and localhost-cert.pem.
  4. Run npm run dev
  5. Load https://localhost:3000/ in a browser and ignore the warning about self-signed certs.

I don't believe that this bug is limited to the example... but it's a good way to reproduce the issue. See "Additional context" for details.

Expected behavior

The server should stay up after responding.

System information

OS: Ubuntu 18.04.3 LTS.
Node: I reproduced this on both v11.15.0 and v8.16.1.
Next.js: v9.0.3

Additional context

Probably caused by: expressjs/compression#128
Probably introduced by: #8066

You can fix it by disabling compression:

const app = next({
  dev,
  conf: {
    compression: false,
  }
})
@knight-of-zero
Copy link
Contributor Author

Related: the docs are slightly off. The option to disable compression is named compress, not compression.

@kyle-ssg
Copy link

Would love to see this, my only lighthouse score reduction is due to non http2 ;)

@kobenauf
Copy link

kobenauf commented Sep 6, 2019

There's a deeper problem beneath the surface here. Currently next-server expects the req to be http.IncomingMessage, not a http2.Http2ServerRequest. As soon as you try to convert the project to typescript, you see this problem. (Also see #8625.)

This means that you might be able to get the project to run, you might run into unknown future problems because your code or other code in your stack are making incorrect assumptions about what the request object is that it's working with. I think the fix to this is going to require some re-work across all the next-server methods, but I could be wrong.

One solution would be for next-server to not use http objects directly as parameters, but instead use an or object that only has the properties/methods that next wants to back. That interface/object would contain a reference to the raw request, whether its http.IncomingMessage or http2.Http2ServerRequest. This would be a breaking affect the method signature of many next-server methods, and it would be a breaking change.

@timneutkens
Copy link
Member

timneutkens commented Jan 2, 2020

Closing this as it's upstream in the compression package and it relies on the custom server api to be implemented.

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants