Skip to content

Getting "414 Request-URI Too Large" when moving contacts on CHT 5.x #799

@binokaryg

Description

@binokaryg

Describe the bug
The move-contacts action fails with a 414 Request-URI Too Large error when the contact being moved has a large number of descendants.

To Reproduce
Steps to reproduce the behavior:

  1. Have a CHT instance running cht-core >= 5.0.0 (Nouveau search path)
  2. Identify a contact with a large number of descendants (e.g. a health center with over 110 contacts under it)
  3. Run: cht --instance=<instance> move-contacts -- --contacts=<contact_id> --parent=<new_parent_id>
  4. Observe the 414 Request-URI Too Large error during the "Processing 0 to 10000 report docs" step

Expected behavior
The move-contacts action should complete successfully regardless of how many descendants the contact has. The descendant IDs should be batched into multiple smaller requests to avoid exceeding URL length limits.

Logs

> cht --instance=***  --user=medic move-contacts "--" --contacts=1f138ea9-8a37-4067-937e-0ed05a32dd7c --parent=12a8b7ac-9d48-4390-8350-74fcd5c7d169
WARN Project has no dependency on cht-conf.
:key:  Password: *************************
INFO Checking that https://medic:****@***/medic/ is available...
WARN Attempting to use project for medic against non-matching instance: https://medic:****@***
Are you sure? [y/n]: y
INFO Processing config in medic.
INFO Actions:
     - move-contacts
INFO Starting action: move-contacts…
INFO Processing 0 to 10000 report docs
INFO StatusCodeError: 414 - "<html>\r\n<head><title>414 Request-URI Too Large</title></head>\r\n<body>\r\n<center><h1>414 Request-URI Too Large</h1></center>\r\n</body>\r\n</html>\r\n"
    at new StatusCodeError (C:\Users\binok\AppData\Roaming\nvm\v22.21.1\node_modules\cht-conf\node_modules\request-promise-core\lib\errors.js:32:15)
    at plumbing.callback (C:\Users\binok\AppData\Roaming\nvm\v22.21.1\node_modules\cht-conf\node_modules\request-promise-core\lib\plumbing.js:104:33)
    at Request.RP$callback [as _callback] (C:\Users\binok\AppData\Roaming\nvm\v22.21.1\node_modules\cht-conf\node_modules\request-promise-core\lib\plumbing.js:46:31)
    at self.callback (C:\Users\binok\AppData\Roaming\nvm\v22.21.1\node_modules\cht-conf\node_modules\request\request.js:185:22)
    at Request.emit (node:events:519:28)
    at Request.<anonymous> (C:\Users\binok\AppData\Roaming\nvm\v22.21.1\node_modules\cht-conf\node_modules\request\request.js:1154:10)
    at Request.emit (node:events:519:28)
    at IncomingMessage.<anonymous> (C:\Users\binok\AppData\Roaming\nvm\v22.21.1\node_modules\cht-conf\node_modules\request\request.js:1076:12)
    at Object.onceWrapper (node:events:633:28)
    at IncomingMessage.emit (node:events:531:35)

Screenshots
N/A

Environment

  • Client platform: Windows
  • cht-conf version: 6.0.2
  • cht-core version: 5.1.0

Additional context
I've never seen this error in earlier version of CHT core (4.x or earlier).

I see that some changes were recently made here specifically for CHT core version >= 5.0.0:

const coreVersion = await getValidApiVersion();
if (coreVersion && semver.gte(coreVersion, NOUVEAU_MIN_VERSION)) {
return await api().getReportsByCreatedByIds(createdByIds, BATCH_SIZE, skip);
}

We might need a batch size smaller than 10000?

Also noticed that, when the number of contacts to move is >= 110 but not too large, it throws 400 instead of 414.

Metadata

Metadata

Assignees

Labels

Type: BugFix something that isn't working as intended

Type

No type

Projects

Status

💻 In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions