Consume rate limiter "req is not defined"

Wappler Version : 6.7.1
Operating System :
Server Model:
Database Type:
Hosting Type:

The Consume Rate LImiter action should not throw this error upon use:

{
    "status": "500",
    "message": "req is not defined",
    "stack": "ReferenceError: req is not defined\n    at App.consume (/opt/node_app/lib/modules/ratelimit.js:37:34)\n    at App._exec (/opt/node_app/lib/core/app.js:703:49)\n    at App._exec (/opt/node_app/lib/core/app.js:670:20)\n    at App.exec (/opt/node_app/lib/core/app.js:639:16)\n    at App.define (/opt/node_app/lib/core/app.js:621:16)\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
}

The fix seems to be to change line 37 of ratelimit.js (add this):

return rateLimiter.consume(this.req.ip, options.points).catch(() => {

Seems that somehow not the latest version of the file was bundled, here is the up-to-date file: ratelimit.zip (1.1 KB)

Thanks Patrick, looks like there were more changes than just my simple hack.

I had hundreds of these errors bring my server down last night...could these be related, or something else?

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821312591Z"}
{"log":"KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821344544Z"}
{"log":"    at Client_MySQL2.acquireConnection (/opt/node_app/node_modules/knex/lib/client.js:332:26)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.82134753Z"}
{"log":"    at async Runner.ensureConnection (/opt/node_app/node_modules/knex/lib/execution/runner.js:305:28)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821349843Z"}
{"log":"    at async Runner.run (/opt/node_app/node_modules/knex/lib/execution/runner.js:30:19)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821352098Z"}
{"log":"    at async App._exec (/opt/node_app/lib/core/app.js:703:22)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821354321Z"}
{"log":"    at async App._exec (/opt/node_app/lib/core/app.js:670:9)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821356576Z"}
{"log":"    at async App.exec (/opt/node_app/lib/core/app.js:639:5)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821358738Z"}
{"log":"    at async App.exec (/opt/node_app/lib/core/app.js:639:5)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821360925Z"}
{"log":"    at async App.define (/opt/node_app/lib/core/app.js:609:7)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821362995Z"}
{"log":"    at async /opt/node_app/lib/setup/sockets.js:148:33\r\n","stream":"stdout","time":"2024-06-24T03:38:34.821365182Z"}
{"log":"This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894629843Z"}
{"log":"KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894659248Z"}
{"log":"    at Client_MySQL2.acquireConnection (/opt/node_app/node_modules/knex/lib/client.js:332:26)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894662154Z"}
{"log":"    at async Runner.ensureConnection (/opt/node_app/node_modules/knex/lib/execution/runner.js:305:28)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894712373Z"}
{"log":"    at async Runner.run (/opt/node_app/node_modules/knex/lib/execution/runner.js:30:19)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.89471565Z"}
{"log":"    at async App._exec (/opt/node_app/lib/core/app.js:703:22)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894717999Z"}
{"log":"    at async App._exec (/opt/node_app/lib/core/app.js:670:9)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894720242Z"}
{"log":"    at async App.exec (/opt/node_app/lib/core/app.js:639:5)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894722309Z"}
{"log":"    at async App.exec (/opt/node_app/lib/core/app.js:639:5)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894724412Z"}
{"log":"    at async App.define (/opt/node_app/lib/core/app.js:609:7)\r\n","stream":"stdout","time":"2024-06-24T03:38:34.89472649Z"}
{"log":"    at async /opt/node_app/lib/setup/sockets.js:148:33\r\n","stream":"stdout","time":"2024-06-24T03:38:34.894728624Z"}

We just released an inline update for nodejs - so just install the updated extension and apply the updates.

Thanks George. Just to be clear, the inline update addresses the connection pool errors I show, as well as the new ratelimit.js, correct?

The pool connection errors simply indicate that no database connection can be made. Maybe there is something else wrong with the database server or the connection info?

No changes there...so far it was a one-off that brought everything down, so I'm just looking for possible recent changes, and the rate limit was a clear suspect. I'll keep looking.

maybe you have uploaded the local database connection settings - instead of the live remote target

Thanks for the idea, but the site was running fine for ~24hours with the new rate limiter and then all db connections would fail. It has about 2k unique users a day so plenty of traffic was going through before the trouble.

@mebeingken try playing with the pool settings for the database connection, set min to 0 and max to 20 or higher.

Installation | Knex.js (knexjs.org)

Thanks Patrick, @apple suggested the same. I've deployed that and will see how it goes.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.