tomve
(Tom)
2023 年11 月 17 日 16:31
1
我以前创建了一个 Discourse 插件,它通过 ajax 调用控制器方法,然后返回结果。这个特定的请求可能需要几分钟才能完成,而且以前运行得很好。
但现在,在很长一段时间后,我在当前的 Discourse 版本中尝试使用该插件时遇到了一个问题,即请求在 1 分钟后被中止。
代码如下:
ajax("/my-plugin/import", {
type: "POST",
data: {
categoryId: this.categoryId,
otherData: ...
}
}).then((result) => { ... });
1 分钟后我看到的错误消息是:
Discourse Ember CLI Proxy Error
FetchError: request to http://127.0.0.1:3000/my-plugin/import failed, reason: socket hang up
at ClientRequest. (file:///src/app/assets/javascripts/node_modules/node-fetch/src/index.js:108:11)
at ClientRequest.emit (node:events:526:35)
at Socket.socketOnEnd (node:_http_client:525:9)
at Socket.emit (node:events:526:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
我想了解的是,为什么这种行为在过去一年里可能会发生变化?以及是否有任何选项可以更改超时设置。
david
(David Taylor)
2023 年11 月 17 日 16:51
2
我认为这里没有发生任何近期更改。Discourse 的后端配置为在开发环境中将请求设置为 60 秒超时,在生产环境中设置为 30 秒超时。
if ENV["RAILS_ENV"] != "production"
logger Logger.new(STDOUT)
# we want a longer timeout in dev cause first request can be really slow
timeout (ENV["UNICORN_TIMEOUT"] && ENV["UNICORN_TIMEOUT"].to_i || 60)
else
# By default, the Unicorn logger will write to stderr.
# Additionally, some applications/frameworks log to stderr or stdout,
# so prevent them from going to /dev/null when daemonized here:
stderr_path "#{discourse_path}/log/unicorn.stderr.log"
stdout_path "#{discourse_path}/log/unicorn.stdout.log"
# nuke workers after 30 seconds instead of 60 seconds (the default)
timeout 30
end
看起来这可以通过 UNICORN_TIMEOUT 环境变量在开发环境中进行配置。但生产环境是硬编码为 30 秒。
2 个赞
tomve
(Tom)
2023 年11 月 30 日 12:46
4
最后,我重写了它以在计划任务中处理导入,事实证明这要好得多。
2 个赞
system
(system)
关闭
2023 年12 月 30 日 12:47
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.