socket hang up after 5000ms #2119
-
|
Hi I am using got library and facing some issue. We are getting socket hangup after a time of 500ms. Do we know what can cause this behavior. The application logs show request leaving client service but the server service doesn't show any request received. Can got have a timeout where it resets connection automatically? some sample code const { body, statusCode, headers, } = await got(url, { |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
"Socket hang up" errors typically occur when the connection is closed unexpectedly, often due to timeouts or network issues. Got doesn't have a hardcoded 5000ms timeout - the default socket timeout is actually undefined (no timeout). Here are some things to check. Configure explicit timeuts: import got from 'got';
await got('https://api.example.com', {
timeout: {
socket: 10000, // 10 seconds of inactivity
response: 30000 // 30 seconds to receive response
},
retry: {
limit: 2
}
});Keep-alive config: If you're using custom agents, make sure keep-alive is configured properly: import https from 'https';
import got from 'got';
const agent = new https.Agent({
keepAlive: true,
keepAliveMsecs: 30000,
maxSockets: 50,
timeout: 10000
});
await got('https://api.example.com', {
agent: {
https: agent
}
});some common causes:
Try adding more detailed error logging to see where the request fails: try {
const response = await got('https://api.example.com');
} catch (error) {
console.log('Error code:', error.code);
console.log('Timings:', error.timings);
console.log('Request options:', error.options);
}The |
Beta Was this translation helpful? Give feedback.
"Socket hang up" errors typically occur when the connection is closed unexpectedly, often due to timeouts or network issues. Got doesn't have a hardcoded 5000ms timeout - the default socket timeout is actually undefined (no timeout).
Here are some things to check.
Configure explicit timeuts:
Keep-alive config:
If you're using custom agents, make sure keep-alive is configured properly: