【问题标题】:Node Cluster module, which is incompatible with PassengerNode Cluster 模块,与Passenger不兼容
【发布时间】:2020-04-12 12:00:47
【问题描述】:

我正在使用 node.js express passport 和最近的 rate-limiter-flexible ...我注意到我收到了以下错误消息:

server.js

const { RateLimiterMemory, RateLimiterRes } = require('rate-limiter-flexible');

控制台错误:

[ N 2019-12-19 17:30:36.7775 15266/Ta age/Cor/CoreMain.cpp:1358 ]: Checking whether to disconnect long-running connections for process 20096, application /var/www/host/project (production)
App 16152 output: Trace: You required the Node Cluster module, which is incompatible with Passenger, a non-functional shim was returned and your app may still work. However, please remove the related code as soon as possible.
App 16152 output:     at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:63:12)
App 16152 output:     at require (internal/modules/cjs/helpers.js:16:16)
App 16152 output:     at Object.<anonymous> (/var/www/host/project/node_modules/rate-limiter-flexible/lib/RateLimiterCluster.js:22:17)
App 16152 output:     at Module._compile (internal/modules/cjs/loader.js:774:30)
App 16152 output:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
App 16152 output:     at Module.load (internal/modules/cjs/loader.js:641:32)
App 16152 output:     at Function.Module._load (internal/modules/cjs/loader.js:556:12)
App 16152 output:     at Module.require (internal/modules/cjs/loader.js:681:19)
App 16152 output:     at Module.require (/usr/share/passenger/helper-scripts/node-loader.js:80:25)
App 16152 output:     at require (internal/modules/cjs/helpers.js:16:16)

这是什么问题,我该如何解决?

【问题讨论】:

  • 你如何使用rate-limiter-flexible包?

标签: javascript node.js express passenger rate-limiting


【解决方案1】:

我认为,它与index.js 有关,其中所有类都被导入,包括RateLimiterCluster。如果你不使用它,你可以尝试通过完整路径要求你需要的确切类

const RateLimiterRedis = require('rate-limiter-flexible/lib/RateLimiterRedis');

【讨论】:

  • 我只使用 RateLimiterMemory。我应该尝试 const RateLimiterMemory = require('rate-limiter-flexible/lib/RateLimiterMemory');对应?
  • 是的。在这里评论,如果有帮助或没有,请
【解决方案2】:

在尝试将我的 NodeJS 应用程序(使用集群模块)部署到具有 cPanel 和“设置 Node.js 应用程序”选项的共享主机中后,我遇到了相同的错误消息。

我建议您阅读的乘客文档中解释了不兼容问题:Fundamental Concepts Phusion Passenger

特别是这部分,它解释了为什么集群模块与乘客不兼容:

Passenger 替换了 Cluster 模块。不需要样板代码:Passenger 可以在多个进程中启动您的应用程序并自动负载平衡流量,大部分时间无需更改代码,如果您已经添加了集群模块样板文件,则将其删除。 除此之外,Passenger 提供的最大优势是它可以通过使用粘性会话来负载平衡 WebSockets、Socket.IO 和 SockJS。这些技术不适用于 Cluster 模块,因为 Cluster 模块的负载平衡机制是通用的(因此无法实现粘性会话),而 Passenger 的机制是专门为 HTTP 编写的。 如果您正在使用Passenger,我们希望您这样做,那么您不能在您的项目中包含集群模块,因为它与Passenger 冲突

【讨论】:

  • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
猜你喜欢
  • 2022-11-29
  • 2021-01-29
  • 2022-10-07
  • 1970-01-01
  • 2012-05-28
  • 2021-03-30
  • 2019-10-30
  • 2021-08-13
相关资源
最近更新 更多