Enhance lock acquisition and error handling in worker service

- Implement retry logic for acquiring file lock with a maximum of 3 attempts.
- Improve error handling for ENOENT errors by ensuring the directory exists before retrying.
- Update context injection handler to delegate to SearchRoutes, reducing code duplication and preventing "headers already sent" errors.
- Add checks for headersSent in error responses to avoid sending multiple responses.
- Log warnings when the port does not free up after shutdown, and handle forced shutdown scenarios more gracefully.
This commit is contained in:
Alex Newman
2025-12-28 14:40:36 -05:00
parent e12a30397d
commit 2d92e8a63f
4 changed files with 106 additions and 98 deletions
+4 -1
View File
@@ -74,9 +74,12 @@ export abstract class BaseRouteHandler {
/**
* Centralized error logging and response
* Checks headersSent to avoid "Cannot set headers after they are sent" errors
*/
protected handleError(res: Response, error: Error, context?: string): void {
logger.failure('WORKER', context || 'Request failed', {}, error);
res.status(500).json({ error: error.message });
if (!res.headersSent) {
res.status(500).json({ error: error.message });
}
}
}