ESLint InterlaceESLint Interlace
Plugin: operabilityRules

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

AspectDetails
SeverityWarning (development)
Auto-FixโŒ No (requires architecture change)
CategoryDevelopment
ESLint MCPโœ… Optimized for ESLint MCP integration
Best ForNode.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

IssueImpactSolution
๐Ÿ”Œ Open connectionsClients receive errorsGraceful shutdown
๐Ÿ’พ Unsaved dataData loss on exitFlush before exit
๐Ÿ”„ Pending requestsInterrupted operationsWait for completion
๐Ÿงน CleanupResources not releasedUse 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);

Further Reading

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 tracked

Mitigation: 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 tracked

Mitigation: Ensure imported values follow the same constraints. Use TypeScript for type safety.

On this page

No Headings