`HeadersTimeoutError` occurs in timeout of more than 5 mins in `fetchAdapter`
arthur19312 opened this issue · comments
Checked other resources
- I added a very descriptive title to this issue.
- I searched the LangChain.js documentation with the integrated search.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain.js rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
Example Code
const result = await fetchAdapter(
{
url: this.url,
method: "POST",
data: JSON.stringify(request),
headers: {
"Content-Type":
this.responseType === "stream"
? "text/event-stream"
: "application/json",
},
responseType: this.responseType || "json",
timeout: this.timeout,
}
).then((res) => (this.responseType === "stream" ? res : res.data));
Error Message and Stack Trace (if applicable)
{
"name": "HeadersTimeoutError",
"code": "UND_ERR_HEADERS_TIMEOUT",
"message": "Headers Timeout Error"
}
Description
HeadersTimeoutError
occurs when I use timeout over 5 mins in fetchAdapter
My azure GPT api sometimes goes to 10 mins while the HeadersTimeoutError
breaks the request at the 5th minute every time when I use the inner fetchAdapter
A related report is https://github.com/nodejs/node/issues/46375
System Info
Mac, Linux
node v18.17.1
yarn 3.4.1
To resolve the HeadersTimeoutError
when using fetchAdapter
with a timeout of more than 5 minutes, you'll need to adjust the timeout
parameter in your request configuration to accommodate longer response times from the Azure GPT API. Specifically, for a 10-minute timeout, set the timeout
value to 600000
milliseconds in your request configuration. Here's how you can modify your existing code:
const result = await fetchAdapter(
{
url: this.url,
method: "POST",
data: JSON.stringify(request),
headers: {
"Content-Type": this.responseType === "stream" ? "text/event-stream" : "application/json",
},
responseType: this.responseType || "json",
timeout: 600000, // Set timeout to 10 minutes in milliseconds
}
).then((res) => (this.responseType === "stream" ? res : res.data));
This adjustment ensures that the request will not be aborted until the specified 10-minute duration has passed, allowing the Azure GPT API sufficient time to respond without triggering a HeadersTimeoutError
.
Details
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
要解决
HeadersTimeoutError
超时fetchAdapter
超过 5 分钟的问题,您需要调整timeout
请求配置中的参数,以适应 Azure GPT API 更长的响应时间。具体来说,对于 10 分钟的超时,请在请求配置中将该timeout
值设置为毫秒。600000
以下是修改现有代码的方法:const result = await fetchAdapter( { url: this.url, method: "POST", data: JSON.stringify(request), headers: { "Content-Type": this.responseType === "stream" ? "text/event-stream" : "application/json", }, responseType: this.responseType || "json", timeout: 600000, // Set timeout to 10 minutes in milliseconds } ).then((res) => (this.responseType === "stream" ? res : res.data));此调整可确保请求在指定的 10 分钟持续时间过去之前不会中止,从而使 Azure GPT API 有足够的时间进行响应,而不会触发
HeadersTimeoutError
.细节
要继续对话,请提及@dosu。
It didn't work by this @dosu
If adjusting the timeout
parameter to 600000 milliseconds in your fetchAdapter
configuration did not resolve the HeadersTimeoutError
, it suggests that the issue might not be solely related to the client-side timeout setting. Here are some steps and considerations to further troubleshoot and potentially resolve the issue:
-
Verify the Timeout Configuration: Double-check that the
timeout
value is correctly applied in thefetchAdapter
call. The value should be in milliseconds, and for a 10-minute timeout, 600000 is correct. -
Network and Server-Side Considerations: Network latency or server-side timeout settings could be affecting your requests. Ensure there are no network issues on your end and verify if the Azure GPT API has its own timeout settings that might be causing the connection to close prematurely.
-
Update or Patch
fetchAdapter
: Look for any updates to thelangchainjs
library or consider patching thefetchAdapter
function if there's a known issue with how timeouts are handled. -
Alternative Fetch Methods: If the problem persists, using a different method for making HTTP requests might offer more robust handling of long timeouts.
Regarding compatibility with Node v18.17.1 and Yarn 3.4.1, there are no known issues that should affect the fetchAdapter
function. The fetchAdapter
is designed to work within the Node environment specified and does not have known limitations on Mac systems.
If these steps do not resolve the issue, providing more details about when the error occurs could help in further diagnosing the problem.
Details
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
Finally I resolved it by adding undici fetch agent : #5245