Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apollo Server timeout while waiting for stream data

I'm attempting to wait for the result of a stream with my Apollo Server. My resolver looks like this.

async currentSubs() {
  try {
    const stream = gateway.subscription.search(search => {
      search.status().is(braintree.Subscription.Status.Active);
    });
    const data = await stream.pipe(new CollectObjects()).collect();
    return data;
  } catch (e) {
    console.log(e);
    throw new Meteor.Error('issue', e.message);
  }
},

This resolver works just fine when the data stream being returned is small, but when the data coming in is larger, I'm getting a 503 (Service Unavailable). I looks like the timeout is happening around 30 seconds. I've tried increasing the timeout of my Express server with graphQLServer.timeout = 240000; but that hasn't made a difference.

How can I troubleshoot this & where is the 30 second timeout coming from? It only fails when the results take longer.

I'm using https://github.com/mrdaniellewis/node-stream-collect to collect the results from the stream.

Error coming in from the try catch:

I20180128-13:09:26.872(-7)? { proxy:
I20180128-13:09:26.872(-7)?    { error: 'Post http://127.0.0.1:26474/graphql: net/http: request canceled (Client.Timeout exceeded while awaiting headers)',
I20180128-13:09:26.872(-7)?      level: 'error',
I20180128-13:09:26.873(-7)?      msg: 'Error sending request to origin.',
I20180128-13:09:26.873(-7)?      time: '2018-01-28T13:09:26-07:00',
I20180128-13:09:26.873(-7)?      url: 'http://127.0.0.1:26474/graphql' } }
like image 561
ToraRTC Avatar asked Jan 28 '18 19:01

ToraRTC


1 Answers

Had this same problem and was a pretty simple solution. My calls were lasting a bit over 30 seconds and the default timeout was returning 503s as well so I increased that.

Assuming you're using apollo-engine (this may be true for some other forms of Apollo), you can set your engine configs like so:

  export function startApolloEngine() {
    const engine = new Engine({
    engineConfig: {
      stores: [
        {
          name: "publicResponseCache",
          memcache: {
            url: [environmentSettings.memcache.server],
            keyPrefix: environmentSettings.memcache.keyPrefix
          }
        }
      ],
      queryCache: {
        publicFullQueryStore: "publicResponseCache"
      },
      reporting: {
        disabled: true
      }
    },
    // GraphQL port
    graphqlPort: 9001,
    origin: {
      requestTimeout: "50s"
    },

    // GraphQL endpoint suffix - '/graphql' by default
    endpoint: "/my_api_graphql",
    // Debug configuration that logs traffic between Proxy and GraphQL server
    dumpTraffic: true
  });

  engine.start();
  app.use(engine.expressMiddleware());
}

Notice the part where I specify

origin: { requestTimeout: "50s" }

That alone is what fixed it for me. Hope this helps!

You can find more information about that here

like image 144
dabyland Avatar answered Nov 14 '22 00:11

dabyland