How do I Fix ERR_SOCKET_TIMEOUT Error on Apollo Gateway

Have more questions? Submit a request

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,
    });
  },
});

Articles in this section

Was this article helpful?
0 out of 0 found this helpful
Share

Comments

0 comments

Please sign in to leave a comment.