使用 URLFetch 发送通道消息的服务时出现 SocketTimeoutException
我们有两个 AppEngine (Java) 应用程序。其中一个使用 URLFetch 到另一个来创建约会。在接收器中,我们添加了一个功能,使用 Channel API 来查看是否有任何开放的通道并让他们知道新数据。
URLFetch 调用失败并出现 SocketTimeoutException。接收器中的所有代码都会执行(包括所有被通知的打开通道),但调用应用程序仍然会收到 SocketTimeoutException。当我注释掉频道通知行时,没有错误。
这种情况仅发生在已部署的应用程序中,而不是在开发模式下。此外,该调用还没有达到 URLFetch 允许的 60 秒(甚至是旧的 10 秒)超时。
We have two AppEngine (Java) apps. One of them uses URLFetch to the other to create an appointment. In the receiver, we've added a feature where we use the Channel API to see if there are any open channels and let them know about the new data.
The URLFetch call is failing with a SocketTimeoutException. All the code in the receiver is executed (including all open channels being notified) but the calling app still gets a SocketTimeoutException. When I comment out the channel notification line, no error.
This happens only in the deployed app, not in dev mode. Also, the call doesn't come close to reaching the 60-second (or even the old 10-second) timeout allowed by URLFetch.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
urlfetch 的默认截止时间是 5 秒,因此如果您的应用程序加载和执行处理程序的时间超过 5 秒,它将返回 SocketTimeoutException 。
如文档中所述,您可以为使用
setConnectTimeout
或setReadTimeout
进行 urlfetch 调用此外,最好将可延迟的 api 调用(即不需要构建 http 响应)移至<一href="https://developers.google.com/appengine/docs/java/taskqueue/" rel="nofollow">任务队列:
The default deadline for urlfetch is 5s, so if your application take more than 5s to load and execute the handler it will return a
SocketTimeoutException
.As described in the documentation, you can set a longer deadline for your urlfetch call using
setConnectTimeout
orsetReadTimeout
In addition, it is a good idea to move the api call that can be deferred (i.e not necessary to build the http response) to a task queue: