At node.js, is right that AbortController.abort() is used to control connection timeout ? (axios time out is for read timeout)

40 Views Asked by At

i'm node.js beginner.

from the axios cancellation doc, i understand that Axios timeout is for read timeout and AbrotController.abort() is for connection time.

when throwing ABORT error, err.message is "canceled" and the message of AXIOS timeout error is "timeout of ~~".

but when i tested it with codes below.

const connectionAbortSignal = (connectionTimeLimit) => {
  const abortController = new AbortController();

  setTimeout(() => abortController.abort(), connectionTimeLimit || 0)
  return abortController.signal
};

const getAnnotationResult = async () => {
  const uri = 'http://httpstat.us/200?sleep=3000'; //return 200 ok in 3 seconds 
  
  const requestConfig = {
    signal: connectionAbortSignal(2000),
    timeout : 1000,
    retryCount: 0
  };

  try {
    const { data } = await axios.get(uri,requestConfig)
    return data;
  } catch (err) {
    throw err.message
  }
};

i send request with curl command, and server got the connecting success message. so, i expected throw AXIOS timeout error. enter image description here

There are two reasons why i was expected that. First, AbortController is for connection timeout and server got connecting success message. Second, respond timeout is 1s and i set response in 3s, so that it will be throw AXIOS timeout error.

but the result is throwing ABORT error.

in case connectionAbortSignal("2000") is less than respond time ('http://httpstat.us/200?sleep=3000'), ABORT error always throws

AbortController.abort() looked like includes read time too, not for connection time. i think it uses one of them to control timout..

is correct that AXIOS timeout uses for read timeout and abortController.abort() uses for connection timeout ?

please explain it. thanks.

so, i expected throw AXIOS timeout error.

0

There are 0 best solutions below