-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Problem
Terminal Output Issue: There's a persistent issue with terminal output that's making debug scripts appear to have empty output
Standalone Node.js scripts hang indefinitely with empty output when executing async operations, while the same code works perfectly when run within a web server context. This creates significant debugging challenges for development workflows.
Environment
Node.js: v18.19.1
OS: Linux (bash shell)
Package Manager: npm
Database: MySQL with connection pooling
Framework: Express.js + TypeScript
Symptoms
✅ Working Cases:
Simple synchronous operations execute normally
Scripts work when run within Express.js server context
Module loading succeeds when stderr is redirected (2>&1)
Synchronous bcrypt operations complete successfully
❌ Failing Cases:
Any script with async operations (Promises, async/await) hangs
Database queries in standalone scripts produce no output
bcrypt async operations (bcrypt.compare()) hang indefinitely
Scripts appear to run but never exit or produce output
Code Pattern Examples
Works fine:
Hangs with empty output:
Investigation Findings
Event Loop Issues: The Node.js event loop appears to stay alive but not process callbacks
Database Connections: Persistent database connections may prevent script termination
Module Loading: Basic module imports work, but async operations within modules fail
Output Buffering: No output is produced, suggesting the issue occurs before any console operations
Workarounds
Impact
Development: Cannot run standalone test scripts for debugging
CI/CD: Automated testing scripts may hang indefinitely
Debugging: Unable to isolate and test individual components
Migration: Difficulty validating migrated functionality
Expected Behavior
Standalone Node.js scripts should execute async operations and exit normally, producing appropriate output or error messages.
Actual Behavior
Scripts hang indefinitely with no output, requiring manual termination.
Additional Context
This issue emerged during a migration from a PHP-based system to Node.js/TypeScript. The same async operations work perfectly when executed within the web server context, suggesting an environment or configuration issue specific to standalone script execution.
Note: This appears to be an environment-specific issue rather than a code logic problem, as the identical code functions correctly in server context.