nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.34k stars 29.48k forks source link

HTTP/2 TypeError(s) #46538

Open khteh opened 1 year ago

khteh commented 1 year ago

Version

v19.6.0

Platform

Linux khteh-p15v-3i 5.19.0-29-generic #30-Ubuntu SMP PREEMPT_DYNAMIC Wed Jan 4 12:14:09 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

const app = next({ dev, dir: __dirname })
app.prepare().then(() => {
  // express setup
  const expressApp = express()
  expressApp.use(express.json())
  expressApp.use(express.urlencoded({ extended: false }))
  expressApp.use(cookieParser())
  expressApp.use(express.static(path.join(__dirname, 'public')))
  //expressApp.use(helmet()) adding set of security middlewares. This breaks!
  expressApp.use(cors()) // enable all CORS request
  expressApp.set('port', port)
  expressApp.use(compression({ filter: shouldCompress }))
  const server = http2.createSecureServer({
    key: fs.readFileSync('server.key'),
    cert: fs.readFileSync('server.crt')
  }, expressApp);
})

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior?

No response

What do you see instead?

error - uncaughtException: TypeError: Cannot read properties of undefined (reading 'readable')
    at IncomingMessage._read (node:_http_incoming:214:19)
    at Readable.read (node:internal/streams/readable:496:12)
    at resume_ (node:internal/streams/readable:999:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
error - uncaughtException: TypeError: Cannot convert undefined or null to object
    at ServerResponse.removeHeader (node:_http_outgoing:813:30)
    at Immediate.write (/usr/src/myapp/node_modules/finalhandler/index.js:282:9)
    at process.processImmediate (node:internal/timers:477:21)
error - uncaughtException: TypeError: Cannot read properties of undefined (reading 'readable')
    at IncomingMessage._read (node:_http_incoming:214:19)
    at Readable.read (node:internal/streams/readable:496:12)
    at resume_ (node:internal/streams/readable:999:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
error - uncaughtException: TypeError: Cannot convert undefined or null to object
    at ServerResponse.removeHeader (node:_http_outgoing:813:30)
    at Immediate.write (/usr/src/myapp/node_modules/finalhandler/index.js:282:9)
    at process.processImmediate (node:internal/timers:477:21)
error - uncaughtException: TypeError: Cannot read properties of undefined (reading 'readable')
    at IncomingMessage._read (node:_http_incoming:214:19)
    at Readable.read (node:internal/streams/readable:496:12)
    at resume_ (node:internal/streams/readable:999:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
error - uncaughtException: TypeError: Cannot convert undefined or null to object
    at ServerResponse.removeHeader (node:_http_outgoing:813:30)
    at Immediate.write (/usr/src/myapp/node_modules/finalhandler/index.js:282:9)
    at process.processImmediate (node:internal/timers:477:21)

Additional information

No response

marco-ippolito commented 1 year ago

can you provide an example without express? I'm afraid the problem is in the interation between http2 server and express

khteh commented 1 year ago

Can you provide an example of using http2 without using express with React.JS/Next.JS application? I tried but no luck.