Page MenuHomePhabricator

EventBus throws TypeError: array_map(): Argument #2 ($array) must be of type array, int given when the event is too large
Open, MediumPublic

Description

Background

As part of T341599: Impact Module: improvements for former newcomers, the Growth team attempted to schedule a job with a significant payload (11143829 bytes). This failed with:

TypeError  array_map(): Argument #2 ($array) must be of type array, int given.

even though the actual error is the event is too large:

core-eventlogging-1  | [2025-07-02T20:26:20.297Z] ERROR: eventgate-devserver/19 on 7d1eaf7b2417: 500: internal_error (message="500: internal_error", status=500, type=internal_error, detail="request entity too large", request_id=0b228b7d902354dccb165e30, levelPath=error/500)
core-eventlogging-1  |     stack: PayloadTooLargeError: request entity too large
core-eventlogging-1  |         at readStream (/opt/eventlogging/node_modules/raw-body/index.js:163:17)
core-eventlogging-1  |         at getRawBody (/opt/eventlogging/node_modules/raw-body/index.js:116:12)
core-eventlogging-1  |         at read (/opt/eventlogging/node_modules/body-parser/lib/read.js:79:3)
core-eventlogging-1  |         at jsonParser (/opt/eventlogging/node_modules/body-parser/lib/types/json.js:138:5)
core-eventlogging-1  |         at Layer.handle [as handle_request] (/opt/eventlogging/node_modules/express/lib/router/layer.js:95:5)
core-eventlogging-1  |         at trim_prefix (/opt/eventlogging/node_modules/express/lib/router/index.js:328:13)
core-eventlogging-1  |         at /opt/eventlogging/node_modules/express/lib/router/index.js:286:9
core-eventlogging-1  |         at Function.process_params (/opt/eventlogging/node_modules/express/lib/router/index.js:346:12)
core-eventlogging-1  |         at next (/opt/eventlogging/node_modules/express/lib/router/index.js:280:10)
core-eventlogging-1  |         at compression (/opt/eventlogging/node_modules/compression/index.js:243:5)
core-eventlogging-1  |         at Layer.handle [as handle_request] (/opt/eventlogging/node_modules/express/lib/router/layer.js:95:5)
core-eventlogging-1  |         at trim_prefix (/opt/eventlogging/node_modules/express/lib/router/index.js:328:13)
core-eventlogging-1  |         at /opt/eventlogging/node_modules/express/lib/router/index.js:286:9
core-eventlogging-1  |         at Function.process_params (/opt/eventlogging/node_modules/express/lib/router/index.js:346:12)
core-eventlogging-1  |         at next (/opt/eventlogging/node_modules/express/lib/router/index.js:280:10)
core-eventlogging-1  |         at next (/opt/eventlogging/node_modules/express/lib/router/route.js:141:14)
core-eventlogging-1  |     --
core-eventlogging-1  |     request: {
core-eventlogging-1  |       "url": "/v1/events",
core-eventlogging-1  |       "headers": {
core-eventlogging-1  |         "x-request-id": "0b228b7d902354dccb165e30",
core-eventlogging-1  |         "content-type": "application/json",
core-eventlogging-1  |         "user-agent": "MediaWiki/1.45.0-alpha",
core-eventlogging-1  |         "content-length": "11143869"
core-eventlogging-1  |       },
core-eventlogging-1  |       "method": "POST",
core-eventlogging-1  |       "params": {
core-eventlogging-1  |         "0": "/v1/events"
core-eventlogging-1  |       },
core-eventlogging-1  |       "query": {},
core-eventlogging-1  |       "remoteAddress": "172.21.0.7",
core-eventlogging-1  |       "remotePort": 53772
core-eventlogging-1  |     }

It seems like EventBus is erroring out with a type error when the target server rejects the event, which is misleading, and it makes it harder for the developer to understand what is going on. For the record, I can reproduce the above mentioned error messages both on my local setup and in Wikimedia production.

Steps to reproduce

In a shell.php session on my local setup (with a working EventBus setup; I used EventLogging's devserver), do the following:

> \MediaWiki\Extension\EventBus\EventBus::getInstanceForStream('foo')->send(['$schema' => '/test/event/1.0.0', 'a' => str_repeat('a', 11143829)])

   TypeError  array_map(): Argument #2 ($array) must be of type array, int given.

>

In the devserver's logs, I can also see the "request entity too large" error (which is the actual issue).

Expected behaviour

The event should either get sent (despite its size), or if that is not possible, EventBus should inform the developer why is that the case, rather than erroring out on "request entity too large".

Actual behaviour

See above, EventBus throws an unrelated fatal error (within the error handling code).