Skip to content

Memory leak while committing transactions in a loop #1163

@ziaratban

Description

@ziaratban

The query request in transaction enhances memory.

CentOS 8
php -v

PHP 7.4.9 (cli) (built: Aug  4 2020 08:28:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.9, Copyright (c), by Zend Technologies

php --ri mongodb

MongoDB support => enabled
MongoDB extension version => 1.7.4
MongoDB extension stability => stable
libbson bundled version => 1.16.2
libmongoc bundled version => 1.16.2
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => disabled
libmongoc ICU => disabled
libmongoc compression => enabled
libmongoc compression snappy => disabled
libmongoc compression zlib => enabled
libmongocrypt bundled version => 1.0.3
libmongocrypt crypto => enabled
libmongocrypt crypto library => libcrypto

Directive => Local Value => Master Value
mongodb.debug => no value => no value

Test case

mongo.php

<?php
echo getmypid()."\n";
echo "sleep(7s)\n";
sleep(7);
echo 'Start';
$mng = new \MongoDB\Driver\Manager('mongodb://user:pass@127.0.0.1:27017/myDb');
$mng->selectServer($mng->getReadPreference());
$session = $mng->startSession();

while(true){
    $session->startTransaction();
    $id = new \MongoDB\BSON\ObjectId('5f721da0e16441233b631842');
    $query = new \MongoDB\Driver\Query(['_id' => $id]);
    $cursor = $mng->executeQuery('myDb.myCollection',$query,['session' => $session]);
    $session->commitTransaction();
    unset($id,$query,$cursor);
}

mongo-monitor.php

<?php
while(true){
    $result = exec("ps -q {$argv[1]} -o rss=",$_,$returnCode);
    if($returnCode !== 0)
        break;
    echo $result."\n";
}

run

root# php mongo.php

105825
sleep(7s)

root# php mongo-monitor.php 105825

why does memory increase?
how i can unset cursor and Free up memory?

thanks.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions