MCPcopy
hub / github.com/vercel/next.js / handleSessionStop

Function handleSessionStop

packages/next/src/cli/next-dev.ts:80–162  ·  view source on GitHub ↗
(signal: NodeJS.Signals | number | null)

Source from the content-addressed store, hash-verified

78)
79
80const handleSessionStop = async (signal: NodeJS.Signals | number | null) => {
81 if (signal != null && child?.pid) child.kill(signal)
82 if (sessionStopHandled) return
83 sessionStopHandled = true
84
85 // Capture the child's exit code if it has already exited and caused the
86 // session stop (via the 'exit' event), otherwise assume success (0).
87 const exitCode = child?.exitCode || 0
88
89 if (
90 signal != null &&
91 child?.pid &&
92 child.exitCode === null &&
93 child.signalCode === null
94 ) {
95 let exitTimeout = setTimeout(() => {
96 child?.kill('SIGKILL')
97 }, CHILD_EXIT_TIMEOUT_MS)
98 await once(child, 'exit').catch(() => {})
99 clearTimeout(exitTimeout)
100 }
101
102 sessionSpan.stop()
103
104 try {
105 const { eventCliSessionStopped } =
106 require('../telemetry/events/session-stopped') as typeof import('../telemetry/events/session-stopped')
107
108 let pagesDir: boolean = !!traceGlobals.get('pagesDir')
109 let appDir: boolean = !!traceGlobals.get('appDir')
110
111 if (
112 typeof traceGlobals.get('pagesDir') === 'undefined' ||
113 typeof traceGlobals.get('appDir') === 'undefined'
114 ) {
115 const pagesResult = findPagesDir(dir)
116 appDir = !!pagesResult.appDir
117 pagesDir = !!pagesResult.pagesDir
118 }
119
120 let telemetry =
121 (traceGlobals.get('telemetry') as InstanceType<
122 typeof import('../telemetry/storage').Telemetry
123 >) ||
124 new Telemetry({
125 distDir: path.join(dir, distDir || '.next'),
126 })
127
128 telemetry.record(
129 eventCliSessionStopped({
130 cliCommand: 'dev',
131 turboFlag: isTurbopack,
132 durationMilliseconds: Date.now() - sessionStarted,
133 pagesDir,
134 appDir,
135 }),
136 true
137 )

Callers 2

next-dev.tsFile · 0.85
startServerFunction · 0.85

Calls 15

findPagesDirFunction · 0.90
saveCpuProfileFunction · 0.90
eventCliSessionStoppedFunction · 0.85
uploadTraceFunction · 0.85
recordMethod · 0.80
killMethod · 0.65
getMethod · 0.65
setTimeoutFunction · 0.50
onceFunction · 0.50
clearTimeoutFunction · 0.50
requireFunction · 0.50
catchMethod · 0.45

Tested by

no test coverage detected