Closed
Description
Bug Overview
The error appears when tries to set more than 3 cookies per request. It loses context during the execution
Stacktrace:
TypeError: Cannot read properties of undefined (reading 'headers_len')
at /usr/local/lib/node_modules/unit-http/http_server.js:157:13
at Array.forEach (<anonymous>)
at ServerResponse._removeHeader (/usr/local/lib/node_modules/unit-http/http_server.js:156:15)
at ServerResponse.setHeader (/usr/local/lib/node_modules/unit-http/http_server.js:89:14)
at ServerResponse.header (/app/node_modules/express/lib/response.js:684:10)
at ServerResponse.append (/app/node_modules/express/lib/response.js:645:15)
at res.cookie (/app/node_modules/express/lib/response.js:777:8)
at file:///app/index.mjs:7:9
at Layer.handleRequest (/app/node_modules/router/lib/layer.js:152:17)
at next (/app/node_modules/router/lib/route.js:157:13)
Expected Behavior
All cookies should be set without any issues
Steps to Reproduce the Bug
The standard guidelines is enough to reproduce that bug
index.mjs
import express from 'express'
const app = express();
app.get('/', (req, res) => {
res.cookie('first', 'cookie', { maxAge: 900000, httpOnly: true })
res.cookie('second', 'cookie', { maxAge: 900000, httpOnly: true })
res.cookie('third', 'cookie', { maxAge: 900000, httpOnly: true })
// ^^^^^ error appears here
res.send('Hello, Express on Unit!')
})
app.listen(8080, () => {
console.log(`Node server is listening on port 8080!`);
});
But just in case i'll provide other files as well
config.json
{
"listeners": {
"*:8080": {
"pass": "applications/ssr"
}
},
"applications": {
"ssr": {
"type": "external",
"processes": {
"max": 50,
"spare": 1
},
"working_directory": "/app",
"executable": "/usr/bin/env",
"environment": {
"version": "{{ '%Y-%m-%d_%H:%M:%S' | strftime }}"
},
"arguments": [
"node",
"--loader",
"unit-http/loader.mjs",
"--require",
"unit-http/loader",
"./index.mjs"
]
}
},
"access_log": {
"path": "/dev/stdout",
"format": "$remote_addr - - [$time_local] \"$request_line\" $status $body_bytes_sent \"$header_referer\" \"$header_user_agent\""
}
}
package.json
{
"name": "ngnixUnitBug",
"version": "1.0.0",
"description": "",
"main": "index.mjs",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"private": true,
"dependencies": {
"express": "^5.1.0"
}
}
docker-compose.yml
services:
ssr:
image: unit:node20
container_name: bug_ssr
working_dir: /app
ports:
- 8081:8080
volumes:
- ./index.mjs:/app/index.mjs
- ./node_modules:/app/node_modules
- ./config.json:/docker-entrypoint.d/config.json
entrypoint: >
/bin/sh -c "
npm link unit-http && \
chown -R unit:unit /run && \
chown -R unit:unit /var/lib/unit && \
chown -R unit:unit /app
/usr/local/bin/docker-entrypoint.sh unitd --no-daemon --control unix:/var/run/control.unit.sock
"
then exec:
docker compose up
open browser: http://localhost:8081
Environment Details
- Target deployment platform: GCP, but it doesnt matter
- Target OS: Mac OS Sequoia v15.5
- Version of this project or specific commit: unit-http: 1.34.2
- Version of any relevant project languages: Kubernetes (version unkown)
Additional Context
No response
Metadata
Metadata
Assignees
Labels
No labels