Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
2838b8b0
Unverified
Commit
2838b8b0
authored
Sep 19, 2025
by
Tobias Koppers
Committed by
GitHub
Sep 19, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Turbopack: add test case that checks memory leak (#83849)
### What? add test case for memory leak
parent
18e7c84a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
159 additions
and
1 deletion
+159
-1
next-rs-api.test.ts
test/development/basic/next-rs-api.test.ts
+159
-1
No files found.
test/development/basic/next-rs-api.test.ts
View file @
2838b8b0
...
@@ -12,7 +12,8 @@ import type {
...
@@ -12,7 +12,8 @@ import type {
UpdateInfo
,
UpdateInfo
,
}
from
'next/dist/build/swc/types'
}
from
'next/dist/build/swc/types'
import
loadConfig
from
'next/dist/server/config'
import
loadConfig
from
'next/dist/server/config'
import
path
from
'path'
import
path
,
{
join
}
from
'path'
import
{
spawnSync
}
from
'child_process'
function
normalizePath
(
path
:
string
)
{
function
normalizePath
(
path
:
string
)
{
return
path
return
path
...
@@ -147,6 +148,163 @@ function appPageCode(text) {
...
@@ -147,6 +148,163 @@ function appPageCode(text) {
export default () => <div>
${
text
}
<Client /></div>;`
export default () => <div>
${
text
}
<Client /></div>;`
}
}
describe
(
'next.rs api writeToDisk multiple times'
,
()
=>
{
it
(
'should allow to write to disk multiple times'
,
async
()
=>
{
let
next
:
NextInstance
next
=
await
createNext
({
skipStart
:
true
,
files
:
{
'pages/index.js'
:
pagesIndexCode
(
'hello world'
),
'lib/props.js'
:
'export default {}'
,
'pages/page-nodejs.js'
:
'export default () => <div>hello world</div>'
,
'pages/page-edge.js'
:
'export default () => <div>hello world</div>
\
nexport const config = { runtime: "experimental-edge" }'
,
'pages/api/nodejs.js'
:
'export default () => Response.json({ hello: "world" })'
,
'pages/api/edge.js'
:
'export default () => Response.json({ hello: "world" })
\
nexport const config = { runtime: "edge" }'
,
'app/layout.tsx'
:
'export default function RootLayout({ children }: { children: any }) { return (<html><body>{children}</body></html>)}'
,
'app/loading.tsx'
:
'export default function Loading() { return <>Loading</> }'
,
'app/app/page.tsx'
:
appPageCode
(
'hello world'
),
'app/app/client.tsx'
:
'"use client";
\
nexport default () => <div>hello world</div>'
,
'app/app-edge/page.tsx'
:
'export default () => <div>hello world</div>
\
nexport const runtime = "edge"'
,
'app/app-nodejs/page.tsx'
:
'export default () => <div>hello world</div>'
,
'app/route-nodejs/route.ts'
:
'export function GET() { return Response.json({ hello: "world" }) }'
,
'app/route-edge/route.ts'
:
'export function GET() { return Response.json({ hello: "world" }) }
\
nexport const runtime = "edge"'
,
'server.js'
:
`
process.title = 'next.rs api run test';
const path = require('path');
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
const loadConfig = require('next/dist/server/config');
const { loadBindings } = require('next/dist/build/swc');
const { createDefineEnv } = require('next/dist/build/swc');
async function main() {
const nextConfig = await loadConfig.default(
PHASE_DEVELOPMENT_SERVER,
__dirname
);
const bindings = await loadBindings();
const rootPath = __dirname;
const distDir = '.next';
const project = await bindings.turbo.createProject({
env: {},
nextConfig: nextConfig,
rootPath,
projectPath: '.',
distDir,
watch: {
enable: true,
},
dev: true,
defineEnv: createDefineEnv({
projectPath: __dirname,
isTurbopack: true,
clientRouterFilters: undefined,
config: nextConfig,
dev: true,
distDir: path.join(rootPath, distDir),
fetchCacheKeyPrefix: undefined,
hasRewrites: false,
middlewareMatchers: undefined,
rewrites: {
beforeFiles: [],
afterFiles: [],
fallback: [],
},
}),
buildId: 'development',
encryptionKey: '12345',
previewProps: {
previewModeId: 'development',
previewModeEncryptionKey: '12345',
previewModeSigningKey: '12345',
},
browserslistQuery: 'last 2 versions',
noMangling: false,
currentNodeJsVersion: '18.0.0',
});
const entrypointsSubscription = project.entrypointsSubscribe();
const entrypoints = (await entrypointsSubscription.next()).value;
const RUNS = 10000;
async function compileRoute(route) {
const endpoint = route.endpoint ?? route.htmlEndpoint ?? route.pages[0].htmlEndpoint;
if (!endpoint) {
console.log('unexpected route', route);
process.exit(1);
}
for (let i = 0; i < RUNS; i++) {
await endpoint.writeToDisk();
}
}
for (const [name, route] of entrypoints.routes) {
console.log(name, route.type);
console.log('first runs');
await compileRoute(route);
gc(true);
let old = process.memoryUsage();
const initial = old;
let stabilized = false;
for (let j = 0; j < 10; j++) {
await compileRoute(route);
gc(true);
const newMemory = process.memoryUsage();
const addedMemory = newMemory.rss - old.rss;
console.log(\`#\${j} \${RUNS} runs add \${addedMemory} bytes of memory, memory since first runs \${newMemory.rss - initial.rss} bytes\`);
old = newMemory;
if (addedMemory === 0) {
console.log('memory usage stabilized');
stabilized = true;
break;
}
}
if (!stabilized) {
console.log('memory usage did not stabilize, failing');
process.exit(1);
}
}
}
main()
.then(() => {
process.exit(0);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
`
,
},
})
const
result
=
spawnSync
(
'node'
,
[
'--expose-gc'
,
join
(
next
.
testDir
,
'server.js'
)],
{
stdio
:
'inherit'
,
env
:
{
...
process
.
env
,
},
}
)
expect
(
result
.
status
).
toBe
(
0
)
await
next
.
destroy
()
})
})
describe
(
'next.rs api'
,
()
=>
{
describe
(
'next.rs api'
,
()
=>
{
let
next
:
NextInstance
let
next
:
NextInstance
beforeAll
(
async
()
=>
{
beforeAll
(
async
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment