l3montree-dev / l3montree-dev/devguard

Registration submission crashes with ERR_HTTP_HEADERS_SENT after middleware fetch failure

Open
#2,761 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)
  ← p / handleResponse (next/dist/esm/build/templates/app-page.js [_not-found/page]:1119)
  ← Module.N [as 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: POST https://main.devguard.org/self-service/registration?flow=b4e9c21d-2488-40f3-9f1d-3e9813e58352
  • Culprit route: POST /_not-found/page
  • Body: registration submission with traits.name, traits.email, confirmedTerms: true (a synthetic/test account, test-user-1785750079714-...)
  • Same trace ID (c617b957c0e14f679065783b5d290202) as issue 3829 — that issue is the Ory Elements client-side error ("unexpected HTML or text response") from this exact registration POST; this event is the underlying Next.js server crash causing that malformed response. A middleware fetch failed (via NextNodeServer.runMiddleware) occurred ~12ms before this error, matching the exact same pattern as issue 3418: a middleware fetch failure triggers Next's not-found/error rendering path after headers were already sent, crashing with ERR_HTTP_HEADERS_SENT and causing the response body Ory Elements receives to be an HTML error page instead of JSON.
  • This confirms the root-cause chain for 3829: middleware fetch failure → ERR_HTTP_HEADERS_SENT crash → malformed/HTML 500 response → Ory Elements SDK throws "unexpected HTML or text response".

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 at the middleware handling for POST /self-service/registration and trace the fetch failure through NextNodeServer.runMiddleware and the /_not-found/page rendering path. Reproduce the synthetic registration request and compare it with issues 3418 and 3829. Done means the failed middleware request produces a valid JSON error without a second response or header write, rather than an HTML error response.

Written by the indexing model from the issue text.

Assessment

Tech stack
next.js, node.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.