Skip to content

Commit 4f47b25

Browse files
committed
identify memory leaks. Attempt 4
1 parent eebadaa commit 4f47b25

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
-e AUTH_URL='${{ vars.AUTH_URL }}' \
7777
-e AUTH_TRUST_HOST=true \
7878
-e NEXT_PUBLIC_URI='${{ vars.NEXT_PUBLIC_URI }}' \
79+
-e HEAP_SNAPSHOT_TOKEN='${{ secrets.HEAP_SNAPSHOT_TOKEN }}' \
7980
-p 3000:3000 \
8081
-p 127.0.0.1:9229:9229 \
8182
ghcr.io/gitranks/gitranks-ui:latest

app/api/_debug/heap/route.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { writeHeapSnapshot } from '@/utils/heap-snapshot';
2+
import { NextResponse } from 'next/server';
3+
4+
export async function GET(request: Request) {
5+
const url = new URL(request.url);
6+
const token = url.searchParams.get('token');
7+
8+
if (token !== process.env.HEAP_SNAPSHOT_TOKEN) {
9+
return new NextResponse('Forbidden', { status: 403 });
10+
}
11+
12+
const file = writeHeapSnapshot();
13+
return NextResponse.json({ file });
14+
}

utils/heap-snapshot.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import v8 from 'v8';
2+
3+
export function writeHeapSnapshot() {
4+
const file = `/tmp/heap-${Date.now()}.heapsnapshot`;
5+
v8.writeHeapSnapshot(file);
6+
console.log('Heap snapshot saved:', file);
7+
return file;
8+
}

0 commit comments

Comments
 (0)