等待流数据时 Apollo Server 超时
Apollo Server timeout while waiting for stream data
我正在尝试使用我的 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' } }
遇到了同样的问题,并且是一个非常简单的解决方案。我的通话持续了 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
我正在尝试使用我的 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' } }
遇到了同样的问题,并且是一个非常简单的解决方案。我的通话持续了 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