FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: handle ECONNRESET gracefully instead of crashing by melvincarvalho · Pull Request #139 · JavaScriptSolidServer/JavaScriptSolidServer · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .js  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions bin/jss.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@ program
process.on('SIGINT', shutdown);
process.on('SIGTERM', shutdown);

// Gracefully handle ECONNRESET — normal network noise from clients
// closing connections early (browser navigation, health checks, etc.)
process.on('uncaughtException', (err) => {
if (err.code === 'ECONNRESET' || err.code === 'EPIPE' || err.code === 'ECONNABORTED') {
return;
}
console.error('Uncaught exception:', err);
process.exit(1);
});

} catch (err) {
console.error(`Error: ${err.message}`);
process.exit(1);
Expand Down
11 changes: 10 additions & 1 deletion src/server.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ export function createServer(options = {}) {
disableRequestLogging: true,
trustProxy: true,
// Handle raw body for non-JSON content
bodyLimit: 10 * 1024 * 1024 // 10MB
bodyLimit: 10 * 1024 * 1024, // 10MB
// Gracefully handle client TCP errors (ECONNRESET, EPIPE, etc.)
clientErrorHandler: (err, socket) => {
if (err.code === 'ECONNRESET' || err.code === 'EPIPE' || err.code === 'ECONNABORTED') {
socket.destroy();
return;
}
// Default Fastify behavior for other client errors
socket.destroy(err);
}
};

// Add HTTPS support if SSL config provided
Expand Down

Back | FazBrowse Home | New Git URL