fix(networkproxy): Improve error handling for proxy requests
This commit is contained in:
parent
3eb4b576a7
commit
70bdf074a1
27
changelog.md
Normal file
27
changelog.md
Normal file
@ -0,0 +1,27 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-10-07 - 3.0.61 - fix(networkproxy)
|
||||
Improve error handling for proxy requests
|
||||
|
||||
- Wrapped proxy request logic in a try-catch block to handle errors gracefully.
|
||||
- Improved error handling for WebSocket communication by checking errors before attempting to send messages.
|
||||
- Added logging for error cases to aid in debugging.
|
||||
|
||||
## 2024-05-29 - 3.0.60 - various updates
|
||||
Maintenance updates and adjustments.
|
||||
|
||||
- Updated project description
|
||||
- Updated tsconfig settings
|
||||
- Updated npmextra.json with new githost info
|
||||
|
||||
## 2023-07-27 - 3.0.58 to 3.0.59 - core improvements
|
||||
Improvements and internal restructuring.
|
||||
|
||||
- Switch to a new organizational scheme
|
||||
- Core updates and adjustments
|
||||
|
||||
## 2022-07-29 - 2.0.16 to 3.0.0 - major transition
|
||||
This release marks a major transition with several breaking changes.
|
||||
|
||||
- BREAKING CHANGE: switched core to ESM (EcmaScript Module)
|
||||
- Major core updates
|
@ -1,8 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
* autocreated commitinfo by @push.rocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartproxy',
|
||||
version: '3.0.60',
|
||||
version: '3.0.61',
|
||||
description: 'a proxy for handling high workloads of proxying'
|
||||
}
|
||||
|
@ -186,6 +186,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
return endOriginReqRes();
|
||||
}
|
||||
console.log(destinationUrl);
|
||||
try {
|
||||
const proxyResponse = await plugins.smartrequest.request(
|
||||
destinationUrl,
|
||||
{
|
||||
@ -202,7 +203,7 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
originRequest.on('data', (data) => {
|
||||
proxyRequest.write(data);
|
||||
});
|
||||
originRequest.on('end', (data) => {
|
||||
originRequest.on('end', () => {
|
||||
proxyRequest.end();
|
||||
});
|
||||
originRequest.on('error', () => {
|
||||
@ -244,6 +245,10 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
originResponse.end();
|
||||
originResponse.destroy();
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error while processing request:', error);
|
||||
endOriginReqRes(502, 'Bad Gateway: Error processing the request');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@ -277,30 +282,44 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
}
|
||||
|
||||
wsIncoming.on('message', async (message, isBinary) => {
|
||||
try {
|
||||
await outGoingDeferred.promise;
|
||||
// console.log("client to upstream", message);
|
||||
wsOutgoing.send(message, { binary: isBinary });
|
||||
} catch (error) {
|
||||
console.error('Error sending message to wsOutgoing:', error);
|
||||
}
|
||||
});
|
||||
|
||||
wsOutgoing.on('message', async (message, isBinary) => {
|
||||
// console.log("upstream to client", message);
|
||||
try {
|
||||
wsIncoming.send(message, { binary: isBinary });
|
||||
} catch (error) {
|
||||
console.error('Error sending message to wsIncoming:', error);
|
||||
}
|
||||
});
|
||||
|
||||
const terminateWsOutgoing = () => {
|
||||
if (wsOutgoing) {
|
||||
wsOutgoing.terminate();
|
||||
console.log('terminated outgoing ws.');
|
||||
}
|
||||
};
|
||||
wsIncoming.on('error', () => terminateWsOutgoing());
|
||||
wsIncoming.on('close', () => terminateWsOutgoing());
|
||||
|
||||
const terminateWsIncoming = () => {
|
||||
if (wsIncoming) {
|
||||
wsIncoming.terminate();
|
||||
console.log('terminated incoming ws.');
|
||||
}
|
||||
};
|
||||
wsOutgoing.on('error', () => terminateWsIncoming());
|
||||
wsOutgoing.on('close', () => terminateWsIncoming());
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
this.httpsServer.keepAliveTimeout = 600 * 1000;
|
||||
this.httpsServer.headersTimeout = 600 * 1000;
|
||||
|
||||
@ -360,7 +379,6 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
cert: hostCandidate.publicKey,
|
||||
key: hostCandidate.privateKey,
|
||||
});
|
||||
this.httpsServer;
|
||||
}
|
||||
}
|
||||
|
||||
@ -379,5 +397,6 @@ JNj2Dr5H0XoLFFnvuvzcRbhlJ9J67JzR+7g=
|
||||
socket.destroy();
|
||||
});
|
||||
await done.promise;
|
||||
console.log('NetworkProxy -> OK: Server has been stopped and all connections closed.');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user