no-process-exit
ESLint rule documentation for no-process-exit
๐ก Live from GitHub โ This documentation is fetched directly from no-process-exit.md and cached for 6 hours.
Keywords: process.exit, Node.js, graceful shutdown, ESLint rule, server, LLM-optimized
Prevents direct process.exit() calls to encourage graceful shutdown patterns. This rule is part of eslint-plugin-operability.
Prevents direct process.exit() calls to encourage graceful shutdown patterns. This rule is part of eslint-plugin-operability.
Quick Summary
| Aspect | Details |
|---|---|
| Severity | Warning (development) |
| Auto-Fix | โ No (requires architecture change) |
| Category | Development |
| ESLint MCP | โ Optimized for ESLint MCP integration |
| Best For | Node.js servers, long-running processes, graceful shutdown |
Rule Details
Direct process.exit() calls terminate the process immediately without allowing cleanup operations, pending I/O, or graceful connection closing.
Why This Matters
| Issue | Impact | Solution |
|---|---|---|
| ๐ Open connections | Clients receive errors | Graceful shutdown |
| ๐พ Unsaved data | Data loss on exit | Flush before exit |
| ๐ Pending requests | Interrupted operations | Wait for completion |
| ๐งน Cleanup | Resources not released | Use exit handlers |
Examples
โ Incorrect
// Direct process.exit
if (error) {
process.exit(1);
}
// In error handlers
process.on('uncaughtException', (err) => {
console.error(err);
process.exit(1); // Immediate termination
});โ Correct
// Use throw for errors
if (error) {
throw new Error('Configuration error');
}
// Graceful shutdown pattern
function gracefulShutdown(signal: string) {
console.log(`Received ${signal}. Starting graceful shutdown...`);
server.close(() => {
console.log('HTTP server closed');
database.close(() => {
console.log('Database connection closed');
// Process will exit naturally
});
});
// Force exit after timeout
setTimeout(() => {
console.error('Forced shutdown after timeout');
process.exit(1); // eslint-disable-line quality/no-process-exit
}, 30000);
}
process.on('SIGTERM', () => gracefulShutdown('SIGTERM'));
process.on('SIGINT', () => gracefulShutdown('SIGINT'));Configuration Examples
Basic Usage
{
rules: {
'operability/no-process-exit': 'warn'
}
}When To Disable
// CLI tools may legitimately use process.exit
// eslint-disable-next-line quality/no-process-exit
process.exit(exitCode);Related Rules
no-console-log- Console logging control
Further Reading
- Node.js process.exit() - Official docs
- Graceful Shutdown - Best practices
Known False Negatives
The following patterns are not detected due to static analysis limitations:
Dynamic Variable References
Why: Static analysis cannot trace values stored in variables or passed through function parameters.
// โ NOT DETECTED - Value from variable
const value = externalSource();
processValue(value); // Variable origin not trackedMitigation: Implement runtime validation and review code manually. Consider using TypeScript branded types for validated inputs.
Wrapped or Aliased Functions
Why: Custom wrapper functions or aliased methods are not recognized by the rule.
// โ NOT DETECTED - Custom wrapper
function myWrapper(data) {
return internalApi(data); // Wrapper not analyzed
}
myWrapper(unsafeInput);Mitigation: Apply this rule's principles to wrapper function implementations. Avoid aliasing security-sensitive functions.
Imported Values
Why: When values come from imports, the rule cannot analyze their origin or construction.
// โ NOT DETECTED - Value from import
import { getValue } from './helpers';
processValue(getValue()); // Cross-file not trackedMitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.