最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - How to use Axios Timeout? - Stack Overflow

programmeradmin0浏览0评论

in my nodeJS server i am sending a post request to AWS (python flask server), the aws-server will take around 30 mins to process the data (because it has certain ML code running) and respond is this a correct way to do the timeout? Because it didn't seem to work.

const awsResponse = await axios.post(`${process.env.AWS_PUBLIC_IP}/aws`, data,
            { timeout: 1800000 } // 30 minutes
 );

(EDIT) Error which i got is..

Error: Request failed with status code 502
AWS Error Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request<p>Reason: <strong>Error reading from remote server</strong></p></p>
</body></html>

in my nodeJS server i am sending a post request to AWS (python flask server), the aws-server will take around 30 mins to process the data (because it has certain ML code running) and respond is this a correct way to do the timeout? Because it didn't seem to work.

const awsResponse = await axios.post(`${process.env.AWS_PUBLIC_IP}/aws`, data,
            { timeout: 1800000 } // 30 minutes
 );

(EDIT) Error which i got is..

Error: Request failed with status code 502
AWS Error Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>502 Proxy Error</title>
</head><body>
<h1>Proxy Error</h1>
<p>The proxy server received an invalid
response from an upstream server.<br />
The proxy server could not handle the request<p>Reason: <strong>Error reading from remote server</strong></p></p>
</body></html>
Share Improve this question edited Feb 1 at 7:11 Pranav K M asked Jan 31 at 18:49 Pranav K MPranav K M 11 bronze badge 2
  • "didn't seem to work." what did you expect to happen and what happened instead? – VLAZ Commented Jan 31 at 19:07
  • If a server has a timeout too, you can't make it longer than it is – Estus Flask Commented Jan 31 at 23:05
Add a comment  | 

1 Answer 1

Reset to default 0

The issue is likely not with Axios itself but rather with the server configuration. Keeping an HTTP connection open for an extended period is generally not a good idea. Here’s what I'll do:

  • Implementing a strategy using webhooks or another mechanism to notify the client when the request succeeds or fails. (See Can we reliably keep HTTP/S connection open for a long time?).

If maintaining a persistent HTTP connection is necessary, I'll configure the server settings accordingly. (See nginx keepalive timeout vs ELB idle timeout vs proxy_read_timeout).

As noted in the reference above, client timeout settings are not relevant if the server’s timeout configuration is shorter than the client’s timeout setting.

发布评论

评论列表(0)

  1. 暂无评论