proxy-chain icon indicating copy to clipboard operation
proxy-chain copied to clipboard

Can't set a request timeout

Open thecatontheflat opened this issue 2 years ago • 1 comments

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?

thecatontheflat avatar Aug 25 '22 09:08 thecatontheflat

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);
    },

thecatontheflat avatar Aug 25 '22 10:08 thecatontheflat

Was something changed with that?

Jakeroid avatar Dec 01 '22 13:12 Jakeroid

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)
})

fnesveda avatar Mar 29 '23 12:03 fnesveda