Joystream / joystream

Joystream Monorepo
http://www.joystream.org
GNU General Public License v3.0
1.42k stars 115 forks source link

Argus trying to set headers after response is set #4760

Closed kdembler closed 1 year ago

kdembler commented 1 year ago

Seeing those in my logs from time to time:

2023-05-15 14:24:22:2422 PublicApi error: middlewareError
{
    "err": {
        "code": "ERR_HTTP_HEADERS_SENT",
        "message": "Cannot set headers after they are sent to the client",
        "stack": "Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client\n    at new NodeError (internal/errors.js:322:7)\n    at ServerResponse.setHeader (_http_outgoing.js:561:11)\n    at PublicApiController.assetHead (/joystream/distributor-node/src/services/httpApi/controllers/public.ts:224:9)\n    at runMicrotasks (<anonymous>)\n    at processTicksAndRejections (internal/process/task_queues.js:95:5)\n    at async /joystream/distributor-node/src/services/httpApi/HttpApiBase.ts:30:9"
    },
    "req": {
        "url": "/api/v1/assets/13702",
        "headers": {
            "host": "joystream.koalva.io",
            "user-agent": "undici",
            "accept": "*/*",
            "accept-encoding": "br, gzip, deflate",
            "accept-language": "*",
            "sec-fetch-mode": "cors",
            "x-forwarded-host": "joystream.koalva.io",
            "x-forwarded-proto": "https"
        },
        "method": "HEAD",
        "httpVersion": "1.1",
        "originalUrl": "/api/v1/assets/13702",
        "query": {}
    }
}
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
    at new NodeError (internal/errors.js:322:7)
    at ServerResponse.setHeader (_http_outgoing.js:561:11)
    at PublicApiController.assetHead (/joystream/distributor-node/src/services/httpApi/controllers/public.ts:224:9)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /joystream/distributor-node/src/services/httpApi/HttpApiBase.ts:30:9
zeeshanakram3 commented 1 year ago

A couple of questions to further investigate this issue:

kdembler commented 1 year ago

Does this error happens only for HEAD assets/ request

No, I've seen this happen also with GET requests

What is the error code of the response

I'm not sure, I think because of the error, the status code doesn't get logged

zeeshanakram3 commented 1 year ago

Fixed in https://github.com/Joystream/joystream/pull/4772