Socket proxying error handling
Summary: More careful error handling as discussed in D35088208. Reviewed By: aigoncharov Differential Revision: D35251661 fbshipit-source-id: 8baab2b454494846411f7084e29c5fa668bc2f31
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3d3e53c9e0
commit
5ce82405f7
@@ -10,7 +10,7 @@
|
||||
import os from 'os';
|
||||
import net from 'net';
|
||||
import express, {Express} from 'express';
|
||||
import http from 'http';
|
||||
import http, {ServerResponse} from 'http';
|
||||
import path from 'path';
|
||||
import fs from 'fs-extra';
|
||||
import {VerifyClientCallbackSync, WebSocketServer} from 'ws';
|
||||
@@ -128,7 +128,20 @@ async function startProxyServer(
|
||||
console.log('Starting socket server on ', socketPath);
|
||||
console.log(`Starting proxy server on http://localhost:${config.port}`);
|
||||
|
||||
proxyServer.on('error', (err, _req, res) => {
|
||||
console.warn('Error in proxy server:', err);
|
||||
if (res instanceof ServerResponse) {
|
||||
res.writeHead(502, 'Failed to proxy request');
|
||||
}
|
||||
res.end('Failed to proxy request: ' + err);
|
||||
});
|
||||
|
||||
proxyServer.on('close', () => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
server.on('close', () => {
|
||||
proxyServer.close();
|
||||
fs.remove(socketPath);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user