GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Starter 서버가 WebCrypto AES 처리 중 Node assertion으로 죽는다 · Issue #82 · project-alone/frontend-boilerplate

Starter 서버가 WebCrypto AES 처리 중 Node assertion으로 죽는다 #82

New issue
Copy link
New issue
Copy link
Closed
#84
Closed
Starter 서버가 WebCrypto AES 처리 중 Node assertion으로 죽는다#82
#84
Copy link
Labels
ready-for-agentFully specified, ready for an AFK agent

Description

@yikl1004
yikl1004
opened on Oct 21, 2026
Issue body actions

Parent

#1

증상

Starter의 서버(next start)가 E2E 도중 Node 내부 assertion으로 죽습니다. 그 뒤의 요청은 모두 ERR_CONNECTION_REFUSED가 되어 테스트 여러 개가 함께 실패합니다.

next-server (v16.4.2): v8::Maybe<void> node::crypto::CipherJob<CipherTraits>::ToResult(...) [with CipherTraits = node::crypto::AESCipherTraits] at ../src/crypto/...
Assertion failed: errors->Empty()
  • master a7480ba의 CI(run 39677592864, Node 24.21.0, harness/showcase-starter.test.ts, dashboard·file-upload E2E 중)에서 한 번 났습니다. 바로 다음 커밋 b122e6e의 CI는 통과했습니다.
  • 로컬(Node 24.10)의 showcase-starter에서도 한 번 본 적이 있습니다.

AES를 쓰는 곳은 auth Recipe의 세션 쿠키(iron-session → WebCrypto AES)뿐입니다. CI만의 문제가 아니라, 실제 배포한 Starter의 서버도 같은 조건에서 죽을 수 있습니다.

Acceptance criteria

  • 재현 방법(또는 재현하지 못했다면 시도한 것)과 근본 원인을 이 이슈에 남긴다. Node의 버그인지, 우리가 WebCrypto를 쓰는 방식 때문인지를 가린다
  • Starter 서버가 이 원인으로 죽지 않게 하는 완화책을 넣거나, 넣을 수 없으면 그 이유와 대안(Node 버전 고정 등)을 남긴다
  • Node에 올릴 upstream 이슈 초안을 남긴다(올리는 것은 사람이 한다)

Activity

  1. yikl1004
    added
    ready-for-agentFully specified, ready for an AFK agent
    on Oct 21, 2026
  2. yikl1004
    added a parent issue on Oct 21, 2026
    • Spec: 프론트엔드 보일러플레이트 1차 — Generator(dcgen)로 Starter 생성·Schematic·Showcase #1
  3. yikl1004 commented on Oct 22, 2026

    @yikl1004
    yikl1004
    on Oct 22, 2026
    ContributorAuthor
    More actions

    진단 결과

    원인을 찾았고 재현도 했다. 고장 두 개가 겹쳐 생긴다.

    1. Node.js 24의 버그(크래시): WebCrypto AES 작업이 끝나면 CipherJob::ToResult가 메인 스레드의 OpenSSL 오류 큐를 읽는데, 거기 남아 있던 남의 오류를 자기 오류로 알고 CHECK(errors->Empty())로 프로세스를 끝낸다. v26.11.0에서 고쳐졌고(crypto: fix various edge cases nodejs/node#66237), v24.x는 최신 v24.22.1까지 그대로다.
    2. Starter에서 그 오류를 남기는 것(트리거): 서버의 MSW가 목 백엔드(https://mock.api.test)와의 TLS 연결을 흉내 내면서 해석할 수 없는 가짜 TLS 세션(Buffer.from('mocked session'))을 내보낸다. Node.js의 fetch(undici)는 이 세션을 기억했다가 같은 주소로 여는 다음 연결의 tls.connect({ session })에 넘긴다. 그러면 Node.js의 TLSWrap::SetSession이 해석에 실패한 세션을 오류 없이 버리면서 ERR_OSSL_ASN1_TOO_LONG을 큐에 남긴다.

    이 오류는 목 백엔드가 응답할 때까지 큐에 남아 있다. 그사이에 다른 요청의 AES 작업이 끝나면 서버가 죽는다. 이 Starter에서 그 AES 작업은 auth Recipe의 iron-session이 세션 쿠키를 AES-256-CBC로 암호화·복호화하는 일이다. 목 백엔드의 응답이 늦을수록 그 사이가 길어지는데, file-upload Recipe의 느린 업로드 핸들러(await delay(SLOW_RESPONSE_MS))가 딱 그렇다. CI에서도 dashboard(로그인할 때 세션 쿠키를 AES로 봉인)와 file-upload E2E가 두 워커에서 함께 돌던 중에 서버가 죽었다.

    우리가 WebCrypto를 잘못 쓴 것이 아니라 Node.js의 버그다. MSW와 undici가 그 버그를 건드릴 오류를 계속 만들어 낸다.

    정정

    이슈 본문에는 CI가 Node.js 24.21.0이라고 되어 있는데, run 39677592864의 setup-node는 .nvmrc의 24를 v24.22.0으로 풀었다(Found in cache @ /opt/hostedtoolcache/node/24.22.0/x64). 크래시 위치 crypto_cipher.h:260도 v24.22.0의 소스와 맞는다.

    증거

    Node.js 소스(v24.22.0)

    • crypto_cipher.h L251-275: ToResult는 메인 스레드(AfterThreadPoolWork)에서 돈다. 자기 오류가 없으면 errors->Capture()로 메인 스레드의 큐를 가져오고, 결과가 있으면(out_.size() > 0) L260에서 CHECK(errors->Empty())를 한다. OpenSSL의 오류 큐는 스레드마다 따로라서, 메인 스레드에서 누가 남긴 오류든 여기 걸린다.
    • crypto_aes.cc L184-193: AES_Cipher는 성공했을 때만 out을 채운다. 그래서 복호화 실패(변조한 쿠키 등)는 오류 경로로 가고 이 CHECK에 걸리지 않는다. 결국 성공한 AES 작업이 남의 오류를 읽을 때만 죽는다.
    • crypto_tls.cc L1965-1982: TLSWrap::SetSession은 GetTLSSession()(d2i_SSL_SESSION)이 실패하면 return; // TODO(tniessen): figure out error handling으로 끝나고, OpenSSL 오류를 지우지 않는다. main과 v26.12.1도 같다.
    • deps/undici/src/lib/core/connect.js L79-101: undici는 'session' 이벤트로 받은 세션을 servername별로 캐시하고, 다음 tls.connect에 session으로 넘긴다.
    • lib/internal/tls/wrap.js L166-192: v24.22.0부터 클라이언트 세션을 servername으로 감싸 검증하고, 검증하는 연결에서는 감싸지 않은 버퍼를 버린다. 하지만 MSW의 가짜 세션도 Node.js가 받을 때 감싸므로 이 검사를 그대로 통과한다.
    • 수정: nodejs/node#66237 안의 커밋 fab9180ee5 "crypto: isolate cipher job errors"가 DoThreadPoolWork에 ClearErrorOnReturn을 넣고, ToResult가 메인 스레드의 큐를 읽지 않게 바꿨다. 이 수정은 v26.11.0에 들어갔고 v24.x에는 backport되지 않았다(PR에 backported-to-v26.x 라벨만 있다). 비슷한 누수로 #66668(scrypt의 maxmem 검사)도 있다.

    MSW 소스: @mswjs/interceptors v0.45.9 socket-controller.ts L1709, L1819-1820. 흉내 낸 TLS 연결이 handle.onnewsession(1, Buffer.from('mocked session'))을 두 번 부르고, getSession()도 같은 버퍼를 돌려준다. MSW 3은 Node.js에서 FetchInterceptor도 결국 진짜 fetch(undici)를 부르고 소켓 단계에서 연결을 흉내 낸다. 그래서 목 백엔드로 가는 요청마다 실제 tls.connect가 불린다.

    E2E 대상 서버에 붙인 탐침: 메인 스레드의 큐가 비었는지 콜백마다 검사했다. crypto.createPrivateKey(올바른 PEM)은 큐에 오류가 있으면 실패하고 그 오류를 비운다.

    상황 결과
    Showcase 목 빌드, Node.js 24.10.0, dashboard+file-upload E2E 큐에 ERR_OSSL_ASN1_TOO_LONG 9번
    같은 빌드, Node.js 24.22.0, 전체 E2E 13번. 세션을 넘긴 tls.connect마다 남고, 세션 없이 연 연결은 깨끗함
    이 이슈의 수정을 넣은 빌드, Node.js 24.22.0, 전체 E2E(111 passed) 0번. 목 백엔드로 연 tls.connect 16번 모두 세션 없음

    남은 오류가 언제까지 살아 있는지도 쟀다. undici의 connect → connected → sendHeaders까지 남아 있다가, 목 백엔드의 응답 헤더가 오기 전에 사라진다. 그래서 응답을 늦추는 핸들러가 있어야 그 사이에 AES 작업이 끝날 틈이 생긴다.

    재현

    MSW 없이 Node.js만으로 재현된다(nodejs/node에 올릴 재현, 아래 초안의 스크립트).

    Node.js 결과
    24.10.0 abort (crypto_cipher.h:245)
    24.22.0 abort (crypto_cipher.h:260, CI와 같음)
    24.22.1 (최신 24.x) abort
    26.10.0 abort (scrypt 누수로 확인)
    26.12.0 통과

    실제 MSW로 Starter와 같은 모양을 재현해도 결과가 같다. 핸들러가 AES 작업을 시작한 뒤 응답을 20ms 늦추고, 요청 3번을 보낸다. 수정 전 Node.js 24.22.0에서 8번 중 8번 abort가 났고, 수정 후에는 8번 모두 통과했다. 이 재현이 PR의 회귀 테스트(base/src/shared/mocks/node.test.ts)다. 하네스의 test-tools.test.ts("Starter의 단위·컴포넌트 테스트가 통과한다")가 Starter의 npm test로 실행한다. 수정 전에는 Worker exited unexpectedly with signal SIGABRT / Assertion failed: errors->Empty()로 실패했고, 수정 후 9개가 모두 통과했다.

    세운 가설

    순위 가설과 예측 결과
    1 ToResult가 메인 스레드에 남은 남의 OpenSSL 오류를 읽는다. 예측: 큐에 오류를 남긴 뒤 성공하는 AES 작업을 돌리면 24.x에서 abort, 고친 버전에서 통과 확인. scrypt 누수와 TLS 세션 누수 둘 다 24.x에서 abort, 26.12.0에서 통과
    2 Starter 안의 무언가가 메인 스레드에 오류를 남긴다. 예측: 탐침에 남은 오류가 잡히고, 그것을 없애면 abort가 사라진다 확인. MSW의 가짜 세션이 남기는 ASN.1 오류였고, 세션을 넘기지 않자 탐침 13번 → 0번, 재현 8/8 → 0/8
    3 iron-session이 아니라 Next.js의 Server Action 암호화(AES-GCM)가 AES 작업을 돌린다 기각. Starter에는 'use server'·'use cache'가 없다. 같은 AESCipherTraits라 GCM으로도 죽지만 이 Starter에서는 iron-session(AES-CBC)이 돌린다
    4 변조했거나 만료된 쿠키를 복호화하다 실패해서 죽는다 기각. AES_Cipher는 실패하면 out을 비워 두므로 오류 경로로 간다
    5 libuv 워커 스레드에 남은 오류가 섞인다 기각. OpenSSL의 오류 큐는 스레드마다 따로다

    완화책

    넣은 것 (#84): Base의 src/shared/mocks/node.ts가 tls.connect를 감싸, 목 백엔드(MOCK_API_BASE_URL의 호스트)로 여는 TLS 연결에는 앞 연결의 세션을 넘기지 않는다.

    • 목 백엔드와의 연결은 MSW가 흉내 내므로 세션을 다시 쓰지 않아도 잃는 것이 없다.
    • node.ts는 MSW를 켤 때만 불러온다(Vitest, 개발 서버, E2E 대상 서버, 목 빌드). MSW를 끈 서버는 그대로다.
    • Base README의 "API 목킹(MSW)"에 이 우회를 적었다. Node.js가 v24.x에서 고치거나 Starter가 Node.js 26 이상으로 올라가면 지워도 된다.

    넣지 않은 것: Node.js 버전 올리기. 크래시 자체는 Node.js ≥ 26.11.0이어야 없어진다. 하지만 Base의 engines.node(^24.11.0), .nvmrc(24), docker Recipe의 이미지(node:24.22.0-trixie-slim), Base GitLab CI의 이미지(node:24-trixie)를 함께 바꿔야 하는 제품 결정이라 손대지 않았다. 참고할 일정은 이렇다. Node.js 24는 2026-10-20에 Maintenance LTS로 넘어갔고, Node.js 26은 2026-10-28에 Active LTS가 된다(nodejs/Release).

    배포한 서버의 위험

    MSW를 끈 서버의 TLS 세션은 실제 서버가 준 올바른 세션이라, 이 트리거로는 죽지 않는다. 다만 Node.js 24의 assertion은 그대로 남아 있다. MSW와 상관없이 메인 스레드에 OpenSSL 오류를 남기는 코드(예: maxmem을 넘는 crypto.scrypt(#66668), 앱이 직접 넘긴 깨진 TLS 세션 등)가 있으면, 배포한 서버도 다음 AES 작업에서 같은 assertion으로 죽는다. 완전히 막으려면 Node.js를 올리거나 v24.x backport를 기다려야 한다.

    사람이 할 일

    1. 아래 초안을 다듬어 nodejs/node에 올린다. v24.x backport 요청과 SetSession 누수 보고를 두 이슈로 나눠도 된다.
    2. Starter의 Node.js를 26 LTS로 올릴지 정한다(위 "넣지 않은 것").
    3. (선택) mswjs/interceptors에 "흉내 낸 TLS 연결이 해석할 수 없는 세션 티켓을 내보내, undici가 그 세션을 다음 연결에 넘기면 Node.js가 OpenSSL 오류를 남긴다"를 알린다. 고쳐지면 이 PR의 우회를 지울 수 있다.
    nodejs/node upstream 이슈 초안 (English)

    Title: crypto: WebCrypto AES job aborts with CHECK(errors->Empty()) in CipherJob::ToResult after an unrelated OpenSSL error is left on the main thread (v24.x); tls setSession leaves such an error

    Version

    v24.22.1 (also v24.10.0, v24.22.0). Not reproducible on v26.12.0.

    Platform

    macOS 26 arm64 (local), Ubuntu 24.04 x64 (GitHub Actions)

    Subsystem

    crypto, tls

    What steps will reproduce the bug?

    // repro.mjs
    import tls from 'node:tls'
    
    const { subtle } = globalThis.crypto
    const key = await subtle.importKey('raw', new Uint8Array(32), 'AES-CBC', false, ['encrypt'])
    
    // 1. A TLS session that d2i_SSL_SESSION() cannot parse. TLSWrap::SetSession
    //    returns without throwing and leaves the ASN.1 error on the main thread's
    //    OpenSSL error queue.
    const socket = tls.connect({
      host: '127.0.0.1',
      port: 9,
      rejectUnauthorized: false, // raw session buffers are only reused for unverified connections since v24.22.0
      session: Buffer.from('not a session'),
    })
    socket.on('error', () => {})
    socket.destroy()
    
    // 2. Any *successful* WebCrypto AES job that completes now aborts the process.
    await subtle.encrypt({ name: 'AES-CBC', iv: new Uint8Array(16) }, key, new Uint8Array(16))
    console.log('ok')

    node repro.mjs

    The same abort happens with any other operation that leaves an error on the main thread's queue, e.g. crypto.scryptSync('pw', 'salt', 32, { N: 2 ** 17 }) (#66668) before the subtle.encrypt() call, and with AES-GCM.

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

    Always with the script above. In a real server it is timing-dependent: the process aborts when a WebCrypto AES job completes while an unrelated OpenSSL error is still queued on the main thread. We hit it with a Next.js server using iron-session (WebCrypto AES-256-CBC for session cookies) while MSW mocked an HTTPS backend. @mswjs/interceptors emits Buffer.from('mocked session') as TLS session tickets, undici caches them per origin and passes them to the next tls.connect({ session }), and the ASN.1 error stays queued until the mocked response arrives.

    What is the expected behavior? Why is that the expected behavior?

    subtle.encrypt() resolves (ok). An unrelated error on the event loop thread's OpenSSL error queue must not crash a successful crypto job. Also, tls.connect({ session }) / socket.setSession() with an unparseable session should either throw or clear the OpenSSL error it caused, instead of silently leaving it for the next OpenSSL consumer.

    What do you see instead?

      #  node[…]: virtual v8::Maybe<void> node::crypto::CipherJob<node::crypto::AESCipherTraits>::ToResult(v8::Local<v8::Value> *, v8::Local<v8::Value> *) [CipherTraits = node::crypto::AESCipherTraits] at ../src/crypto/crypto_cipher.h:260
      #  Assertion failed: errors->Empty()
    
    ----- Native stack trace -----
     …
     3: node::crypto::CipherJob<node::crypto::AESCipherTraits>::ToResult(…)
     4: node::crypto::CryptoJob<node::crypto::AESCipherTraits>::AfterThreadPoolWork(int)
     …
    Aborted (core dumped)
    

    Additional information

    • CipherJob::ToResult (v24.22.0 src/crypto/crypto_cipher.h#L251-L275) runs on the event loop thread, calls errors->Capture() when the job has no errors of its own, and then CHECK(errors->Empty()) when out_.size() > 0. OpenSSL error queues are per thread, so it captures whatever any other code left on the main thread.
    • This was fixed on main by fab9180ee5 ("crypto: isolate cipher job errors", part of #66237) and released in v26.11.0. #66237 carries only backported-to-v26.x. Could the CipherJob part be backported to v24.x? It turns an unrelated, otherwise harmless OpenSSL error into a process abort on the current LTS line.
    • Separately, TLSWrap::SetSession (src/crypto/crypto_tls.cc, unchanged on main) returns on GetTLSSession() == nullptr with // TODO(tniessen): figure out error handling and leaves the d2i_SSL_SESSION error (ERR_OSSL_ASN1_TOO_LONG) queued. On v26.12.0 the abort is gone, but the leak is still there: a following crypto.createPrivateKey(validPem) throws ERR_OSSL_ASN1_TOO_LONG, the same class of bug as #66668, #45485 and #21281. A ClearErrorOnReturn (or throwing ERR_TLS_INVALID_SESSION) in SetSession would fix it.
  4. yikl1004
    closed this as completedin #84on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ready-for-agentFully specified, ready for an AFK agent

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.