【问题标题】:Apollo Server timeout while waiting for stream dataApollo 服务器在等待流数据时超时
【发布时间】:2018-07-07 12:03:19
【问题描述】:

我正在尝试使用我的 Apollo 服务器等待流的结果。我的解析器看起来像这样。

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 (Service Unavailable)。我看起来超时发生在 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 服务器是直接连接的,还是在负载均衡器或代理或反向代理或类似的东西后面?
  • 您增加超时的方式不正确。你是如何启动你的服务器的,你使用的是 apollo-engine 还是 apollo-server 或 apolloExpress 等 :)
  • @JoeWarner 我通过github.com/apollographql/meteor-integration使用apollo-server v1

标签: node.js graphql braintree apollo apollo-server


【解决方案1】:

遇到了同样的问题,并且是一个非常简单的解决方案。我的通话持续了 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" }

仅此一项就为我解决了问题。希望这会有所帮助!

你可以找到更多关于here的信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-06
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多