From 7e2f629681135e50daeb575cd154473ede8fe7df Mon Sep 17 00:00:00 2001 From: jisangs Date: Sat, 4 Jul 2026 17:48:33 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=EC=97=90=EC=84=9C=20query=20=EA=B2=B0=EA=B3=BC=EA=B0=80=20?= =?UTF-8?q?=EC=9E=98=EB=A0=A4=EB=B3=B4=EC=9D=B4=EB=8A=94=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=EC=88=98=EC=A0=95=20(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/db.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/db.ts b/lib/db.ts index 32aee1b..55d7bb9 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -12,6 +12,21 @@ const globalForPrisma = globalThis as unknown as { const SLOW_QUERY_MS = Number(process.env.DB_SLOW_QUERY_MS ?? "1000"); +// Docker 파이프 환경에서 stdout fd는 non-blocking이라 writeSync가 부분 쓰기를 +// 하거나 EAGAIN을 던질 수 있다. 전부 쓸 때까지 반복해 로그 유실을 막는다. +function writeAll(fd: number, text: string): void { + const buf = Buffer.from(text, "utf8"); + let offset = 0; + while (offset < buf.length) { + try { + offset += writeSync(fd, buf, offset, buf.length - offset); + } catch (err) { + if ((err as NodeJS.ErrnoException).code === "EAGAIN") continue; + throw err; + } + } +} + // ── SQL 로깅 ($on) ──────────────────────────────────────────────── function inlineParams(query: string, rawParams: string): string { @@ -49,7 +64,7 @@ function onQuery(e: Prisma.QueryEvent): void { .join("\n"); const out = `${header}\n${indented}\n`; - writeSync(isSlow ? 2 : 1, out); + writeAll(isSlow ? 2 : 1, out); } // ── 결과 로깅 ($extends) ────────────────────────────────────────── @@ -196,7 +211,7 @@ function logResult( if (!logger.isEnabled("debug")) return; const ts = new Date().toISOString(); const body = buildResultLog(model, operation, result); - writeSync(1, `[${ts}] [DEBUG] [db:result] ${body}\n`); + writeAll(1, `[${ts}] [DEBUG] [db:result] ${body}\n`); } // ── PrismaClient 생성 ─────────────────────────────────────────────