2025-09-25T09:08:34.162Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.161+00:00"},"s":"I", "c":"NETWORK", "id":6788700, "ctx":"conn80","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":2}}
2025-09-25T09:08:34.162Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.162+00:00"},"s":"I", "c":"COMMAND", "id":21577, "ctx":"conn80","msg":"Initiate: no configuration specified. Using a default configuration for the set"}
2025-09-25T09:08:34.162Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.162+00:00"},"s":"I", "c":"COMMAND", "id":21578, "ctx":"conn80","msg":"Created configuration for initiation","attr":{"config":{"_id":"rs0","version":1,"members":[{"_id":0,"host":"666818ea5142:27017"}]}}}
2025-09-25T09:08:34.162Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.162+00:00"},"s":"I", "c":"REPL", "id":21356, "ctx":"conn80","msg":"replSetInitiate admin command received from client"}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.167Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.166+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn79","msg":"Connection ended","attr":{"remote":"127.0.0.1:43720","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"a9480a47-939b-4d5a-978f-fc8fe7a08165"}},"connectionId":79,"connectionCount":4}}
2025-09-25T09:08:34.167Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.166+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn76","msg":"Connection ended","attr":{"remote":"127.0.0.1:43686","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"35b13d63-89b3-4bab-b36d-f6e961a21092"}},"connectionId":76,"connectionCount":3}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.167Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.166+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn78","msg":"Connection ended","attr":{"remote":"127.0.0.1:43714","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"5dfa454c-6f50-44f0-bdb1-b168ae7b0229"}},"connectionId":78,"connectionCount":2}}
2025-09-25T09:08:34.167Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.166+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn80","msg":"Connection ended","attr":{"remote":"127.0.0.1:43732","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"f5463634-b201-4a16-9013-264168499a7c"}},"connectionId":80,"connectionCount":1}}
2025-09-25T09:08:34.167Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.166+00:00"},"s":"I", "c":"NETWORK", "id":22944, "ctx":"conn77","msg":"Connection ended","attr":{"remote":"127.0.0.1:43698","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"873968be-b359-4e74-b8bb-7e00dddc898d"}},"connectionId":77,"connectionCount":0}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.677Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.676+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:43738","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"5396470b-fb96-4f02-87fa-cbdbd35c005c"}},"connectionId":81,"connectionCount":1}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.679Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.678+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn81","msg":"client metadata","attr":{"remote":"127.0.0.1:43738","client":"conn81","negotiatedCompressors":[],"doc":{"application":{"name":"mongosh 2.5.6"},"driver":{"name":"nodejs|mongosh","version":"6.16.0|2.5.6"},"platform":"Node.js v20.19.4, LE","os":{"name":"linux","architecture":"arm64","version":"4.14.209-160.339.amzn2.aarch64","type":"Linux"},"env":{"container":{"runtime":"docker"}}}}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.720Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.719+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:43754","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"b491bb8a-927b-4dfc-9aaf-f8b2d06b72ee"}},"connectionId":82,"connectionCount":2}}
2025-09-25T09:08:34.720Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.719+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:43760","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"a179462c-6131-42e1-a5da-cafd8d6c4f22"}},"connectionId":83,"connectionCount":3}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.720Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.719+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn82","msg":"client metadata","attr":{"remote":"127.0.0.1:43754","client":"conn82","negotiatedCompressors":[],"doc":{"application":{"name":"mongosh 2.5.6"},"driver":{"name":"nodejs|mongosh","version":"6.16.0|2.5.6"},"platform":"Node.js v20.19.4, LE","os":{"name":"linux","architecture":"arm64","version":"4.14.209-160.339.amzn2.aarch64","type":"Linux"},"env":{"container":{"runtime":"docker"}}}}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.721Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.720+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn83","msg":"client metadata","attr":{"remote":"127.0.0.1:43760","client":"conn83","negotiatedCompressors":[],"doc":{"application":{"name":"mongosh 2.5.6"},"driver":{"name":"nodejs|mongosh","version":"6.16.0|2.5.6"},"platform":"Node.js v20.19.4, LE","os":{"name":"linux","architecture":"arm64","version":"4.14.209-160.339.amzn2.aarch64","type":"Linux"},"env":{"container":{"runtime":"docker"}}}}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.722Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.722+00:00"},"s":"I", "c":"NETWORK", "id":6788700, "ctx":"conn82","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":2}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.723Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.722+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:43762","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"0a3db8a0-36fa-492b-ae7e-ead0ced31d85"}},"connectionId":84,"connectionCount":4}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.723Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.723+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"127.0.0.1:43770","isLoadBalanced":false,"uuid":{"uuid":{"$uuid":"08528504-3252-40c7-89fa-7439b1bbe6b9"}},"connectionId":85,"connectionCount":5}}
stdout | packages/modules/mongodb/src/mongodb-container.test.ts > MongoDBContainer > should have low CPU usage
2025-09-25T09:08:34.724Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.723+00:00"},"s":"I", "c":"COMMAND", "id":21577, "ctx":"conn82","msg":"Initiate: no configuration specified. Using a default configuration for the set"}
2025-09-25T09:08:34.724Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.723+00:00"},"s":"I", "c":"COMMAND", "id":21578, "ctx":"conn82","msg":"Created configuration for initiation","attr":{"config":{"_id":"rs0","version":1,"members":[{"_id":0,"host":"666818ea5142:27017"}]}}}
2025-09-25T09:08:34.724Z testcontainers:containers [666818ea5142] {"t":{"$date":"2025-09-25T09:08:34.723+00:00"},"s":"I", "c":"REPL", "id":21356, "ctx":"conn82","msg":"replSetInitiate admin command received from client"}
Expected Behaviour
MongoDBContainer should not consume excessive amounts of CPU
Actual Behaviour
After starting MongoDBContainer, it consumes 50-100% of 1 CPU core, due to repeated replicaset re-initialization
Testcontainer Logs
Steps to Reproduce
docker statsto show container CPU usage (but isn't actually asserting correct CPU usage):npx vitest run packages/modules/mongodb/src/mongodb-container.test.ts -t "should have low CPU usage" --silent=false |& grep "======" | grep -v "testcontainers-"Sample CPU usage stats, after that change (run
git checkout c0571da):Sample CPU usage stats, before that change (
git checkout c0571da^):Environment Information
(Note, environment / architecture likely doesn't matter to reproduce this issue)