canonical / canonical/mongodb-operator

Allow TasksMax=infinity to avoid "Pthread_create failed" error

Open
#576 2 comments 1 reaction 0 assignees View on GitHub
bug
Dominant language
HCL
Stars
14
Forks
15
Avg merge
9h 44m
Merged PRs (30d)
17

Description

## Steps to reproduce

Deploy mongodb and relate with 26 units.

## Expected behavior

System is operational. The charm either sets

```
[Service]
TasksMax=infinity
```
in `snap.charmed-mongodb.mongod.service`

or allows to set it via charm configuration.

## Actual behavior

We observed connection drops from clients and observed log lines like

```
{"t":{"$date":"2025-09-04T07:34:26.741+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"10.141.131.64:52308","uuid":"428dcb73-907e-4568-82e0-0e6244b12375","connectionId":20688,"connectionCount":4585}}
{"t":{"$date":"2025-09-04T07:34:26.758+00:00"},"s":"E", "c":"-", "id":4850900, "ctx":"listener","msg":"pthread_create failed","attr":{"error":"Resource temporarily unavailable"}}
{"t":{"$date":"2025-09-04T07:34:26.758+00:00"},"s":"E", "c":"-", "id":22948, "ctx":"listener","msg":"Thread creation failed","attr":{"error":"pthread_create failed"}}
{"t":{"$date":"2025-09-04T07:34:26.758+00:00"},"s":"W", "c":"EXECUTOR", "id":22993, "ctx":"listener","msg":"Unable to schedule a new loop for the service state machine","attr":{"error":{"code":1,"codeName":"InternalError","errmsg":"Failed to create service entry worker thread: pthread_create failed"}}}
```

indicating that pthread_create failed. After finding https://www.mongodb.com/community/forums/t/pthread-create-failed-resource-temporarily-unavailable-in-mongo/100392 we saw that the Task Limit was reached

```
sudo systemctl status snap.charmed-mongodb.mongod.service
● snap.charmed-mongodb.mongod.service - Service for snap application charmed-mongodb.mongod
Loaded: loaded (/etc/systemd/system/snap.charmed-mongodb.mongod.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2025-09-04 06:33:41 UTC; 2h 41min ago
Main PID: 632 (mongod)
Tasks: 4647 (limit: 4647)
Memory: 1.5G
CPU: 1h 27min 31.481s
CGroup: /system.slice/snap.charmed-mongodb.mongod.service
└─632 /snap/charmed-mongodb/131/usr/bin/mongod --config /var/snap/charmed-mongodb/131/etc/mongod/mongod.conf --bind_ip_all --replSet=mongodb --dbpath=/var/snap/charmed-mo>
```

We could fix it by setting the TaskLimit to infinity, as outlined in the article above

```
ubuntu@juju-3918b7-prod-ps6-github-runner-33:~$ cat /etc/systemd/system/snap.charmed-mongodb.mongod.service.d/override.conf
[Service]
TasksMax=infinity
```

## Versions

Operating system: Ubuntu 22.04.5 LTS

Juju CLI: 3.6.8-ubuntu-amd64

Juju agent: 3.6.9

Charm revision: 224

LXD:

## Log output

Juju debug log:

## Additional context

Contributor guide

Open the contributing guide

Research direction

Start by locating how the charm generates snap.charmed-mongodb.mongod.service and whether it exposes service-level configuration. Reproduce the 26-unit deployment and inspect the service's Tasks limit; done means the charm sets TasksMax=infinity or provides a configuration path, with the pthread_create failure no longer caused by the task limit.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb
Domain
databases, infrastructure
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.