Skip to content
Discussion options

You must be logged in to vote

"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,
	

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants