proxy-chain
proxy-chain copied to clipboard
Can't set a request timeout
I can't seem to find a way to set the request timeout out of the box. For example, if the target URL is not responding, it will just hang the socket.
I am going to solve it by handling the timeout myself via setTimeout()
and checking if there was any response in the socket, but maybe I'm missing a more straightforward way?
I guess something like this works?
prepareRequestFunction: ({ request, username, password, hostname, port, isHttp, connectionId }) => {
// If we received no data, we should release the socket
const connectionTimeout = 1 * 1000;
setTimeout(() => {
const stats = server.getConnectionStats(connectionId);
if (stats && stats.srcTxBytes === 0) {
server.closeConnection(connectionId);
console.log('Releasing hanged connection');
}
}, connectionTimeout);
},
Was something changed with that?
This should be rather solved on the client side, see e.g. the Axios docs for how to do it: https://axios-http.com/docs/cancellation
In short:
const response = await axios.get('https://example.com', {
signal: AbortSignal.timeout(5000)
})