l3montree-dev / l3montree-dev/devguard

Login redirect crashes with ERR_HTTP_HEADERS_SENT after middleware fetch failure

Open
#2,746 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug component/devguard-web priority:high
Dominant language
Go
Stars
161
Forks
43
Avg merge
1d 8h
Merged PRs (30d)
37

Description

Error

Error: Cannot append headers after they are sent to the client

Stack trace

ServerResponse.appendHeader (node:_http_outgoing:746)
  ← handleResponse (next/dist/esm/build/templates/app-page.js [_not-found/page]:1119)
  ← handler (next/dist/esm/build/templates/app-page.js [_not-found/page]:1326)
  ← NextNodeServer.renderToResponseWithComponentsImpl (next/dist/server/base-server.js:1462)
  ← NextNodeServer.renderErrorToResponseImpl (next/dist/server/base-server.js:1808)
  ← pipe.req.req (next/dist/server/base-server.js:1660)
  ← NextNodeServer.pipeImpl (next/dist/server/base-server.js:1044)
  ← invokeRender (next/dist/server/lib/router-server.js:266)
  ← handleRequest (next/dist/server/lib/router-server.js:505)

Source (node_modules/next/dist/esm/build/templates/app-page.js:1114-1124, page=/_not-found/page)

                        }
                    } else if (typeof value === 'number') {
                        value = value.toString();
                        res.appendHeader(key, value);
                    } else {
                        res.appendHeader(key, value);
                    }
                }
            }
            // Add the cache tags header to the response if it exists and we're in
            // minimal mode while rendering a static page.

Request context

  • URL: https://app.devguard.org/self-service/login/browser
  • Culprit route: GET /_not-found/page
  • A middleware fetch failed (TypeError, via NextNodeServer.runMiddleware) occurred ~15ms before this error, which appears to have triggered Next's not-found/error rendering path on a response whose headers were already sent, causing the ERR_HTTP_HEADERS_SENT crash.

GlitchTip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the GET /self-service/login/browser request through NextNodeServer.runMiddleware and the not-found rendering path in next/dist/esm/build/templates/app-page.js:1114-1124. Reproduce the middleware fetch failure and inspect when response headers are sent before handleResponse calls appendHeader. Done means the request no longer crashes with ERR_HTTP_HEADERS_SENT after that failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.