On an Apollo Gateway with high traffic, you might encounter the following error:
{
code: ERR_SOCKET_TIMEOUT,
timeout: 4000,
type: system,
errorType: FetchError
formattedErrorMessage: reason: Socket timeout
}
This is caused by the default connection pooling limit set in make-fetch-happen
, a library that Apollo Gateway uses for HTTP requests. The default limit for older versions of the library is 15 connections.
To fix this error, please update your @apollo/gateway
package to v0.51.0 or later (or v2.0.2+ if you're using Federation 2.x). These versions remove the connection limit entirely and will resolve this issue.
Setting a connection limit manually
If needed, you can set a connection limit manually by creating a fetcher
object with the make-fetch-happen
library, and pass that fetcher
into the gateway buildService
.
import fetcher from 'make-fetch-happen';
const lowConcurrencyFetcher = fetcher.defaults({ maxSockets: 15 });
const gateway = new ApolloGateway({
buildService({ url }) {
return new RemoteGraphQLDataSource({
url,
fetcher: lowConcurrencyFetcher,
});
},
});
Comments
0 commentsPlease sign in to leave a comment.