Apollo Server 在等待流数据时超时了。

13

我试图使用Apollo Server等待流的结果。我的解析器如下所示。

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

这个解析器在返回的数据流很小的时候可以正常工作,但是当输入的数据变大时,会出现503(服务不可用)的错误。看起来超时时间大约是30秒。我已经尝试通过graphQLServer.timeout = 240000;增加我的Express服务器的超时时间,但没有任何改变。

我该如何排除故障并确定这个30秒的超时时间是从哪里引起的?它只在结果需要更长时间时才失败。

我正在使用https://github.com/mrdaniellewis/node-stream-collect来收集流中的结果。

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' } }

你能多说一些关于你的基础设施吗?Apollo服务器是直接连接的,还是在负载均衡器、代理服务器、反向代理服务器或其他类似的东西后面? - tremby
你增加超时时间的方式是不正确的。你是怎样启动你的服务器的?你使用的是apollo-engine还是apollo-server或者是apolloExpress等呢 :) - Joe Warner
@JoeWarner 我正在使用 https://github.com/apollographql/meteor-integration 通过 apollo-server v1。 - ToraRTC
1个回答

9

我遇到了同样的问题,解决方案非常简单。我的调用持续了30秒以上,而默认超时时间也返回了503s,所以我将其增加了。

假设您正在使用apollo-engine(对于其他形式的Apollo可能也适用),您可以像这样设置引擎配置:

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

请注意我指定的部分

origin: { requestTimeout: "50s" }

仅仅这样就解决了我的问题。希望能对你有所帮助!
你可以在这里找到更多相关信息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接