influxdata / influxdata/influxdb-client-php

memory leak when repeatedly connecting while using HTTPS

Open
#137 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
166
Forks
52
PR merge metrics
No merged PRs in 30d

Description

Steps to reproduce:

<?php
require_once('vendor/autoload.php');

use InfluxDB2\Client;
use InfluxDB2\Model\WritePrecision;
use InfluxDB2\Point;

$token = 'token';
$org = 'Home';
$bucket = 'default';

while (1) {
  $client = new Client([
    "url" => "https://influx:8086",
    "token" => $token,
  ]);


  $dataArray = ['name' => 'test',
    'fields' => array('xxx' => 123),
  ];

  $writeApi = $client->createWriteApi();
  $writeApi->write($dataArray, WritePrecision::MS, $bucket, $org);

  $writeApi->close();
  unset($writeApi);
  unset($dataArray);
  $client->close();
  unset($client);
}

Expected behavior:
Memory usage doesn't increase that heavily.

Actual behavior:
Memory usage does increase heavily. I dumped the memory, it seems to be related to CA certificates. I was able to find thousands of instances of each CA certificate in php memory.

Also I get this error after 10-20 seconds:

PHP Fatal error:  Uncaught Http\Client\Exception\RequestException: error setting certificate file: /etc/ssl/certs/ca-certificates.crt in /home/kveri/goodwe/vendor/php-http/curl-client/src/Client.php:166
Stack trace:
#0 /home/kveri/goodwe/vendor/php-http/client-common/src/PluginClient.php(81): Http\Client\Curl\Client->sendRequest()
#1 /home/kveri/goodwe/vendor/php-http/client-common/src/Plugin/RedirectPlugin.php(175): Http\Client\Common\PluginClient->Http\Client\Common\{closure}()
#2 /home/kveri/goodwe/vendor/php-http/client-common/src/PluginChain.php(46): Http\Client\Common\Plugin\RedirectPlugin->handleRequest()
#3 /home/kveri/goodwe/vendor/php-http/client-common/src/Plugin/HeaderDefaultsPlugin.php(44): Http\Client\Common\PluginChain->Http\Client\Common\{closure}()
#4 /home/kveri/goodwe/vendor/php-http/client-common/src/PluginChain.php(46): Http\Client\Common\Plugin\HeaderDefaultsPlugin->handleRequest()
#5 /home/kveri/goodwe/vendor/php-http/client-common/src/PluginChain.php(61): Http\Client\Common\PluginChain->Http\Client\Common\{closure}()
#6 /home/kveri/goodwe/vendor/php-http/client-common/src/PluginClient.php(87): Http\Client\Common\PluginChain->__invoke()
#7 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(151): Http\Client\Common\PluginClient->sendRequest()
#8 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(214): InfluxDB2\DefaultApi->sendRequest()
#9 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(79): InfluxDB2\DefaultApi->request()
#10 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteApi.php(145): InfluxDB2\DefaultApi->post()
#11 [internal function]: InfluxDB2\WriteApi->InfluxDB2\{closure}()
#12 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteRetry.php(70): call_user_func()
#13 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteApi.php(146): InfluxDB2\WriteRetry->retry()
#14 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteApi.php(86): InfluxDB2\WriteApi->writeRaw()
#15 /home/kveri/goodwe/xxx.php(24): InfluxDB2\WriteApi->write()
#16 {main}

Next InfluxDB2\ApiException: [0] error setting certificate file: /etc/ssl/certs/ca-certificates.crt in /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php:179
Stack trace:
#0 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(214): InfluxDB2\DefaultApi->sendRequest()
#1 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php(79): InfluxDB2\DefaultApi->request()
#2 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteApi.php(145): InfluxDB2\DefaultApi->post()
#3 [internal function]: InfluxDB2\WriteApi->InfluxDB2\{closure}()
#4 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteRetry.php(70): call_user_func()
#5 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteApi.php(146): InfluxDB2\WriteRetry->retry()
#6 /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/WriteApi.php(86): InfluxDB2\WriteApi->writeRaw()
#7 /home/kveri/goodwe/xxx.php(24): InfluxDB2\WriteApi->write()
#8 {main}
  thrown in /home/kveri/goodwe/vendor/influxdata/influxdb-client-php/src/InfluxDB2/DefaultApi.php on line 179

Specifications:

  • Client Version: 3.2.0
  • InfluxDB Version: 2.6.0
  • Platform: x86_64 ubuntu

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction script and the certificate-related failure at vendor/php-http/curl-client/src/Client.php:166, then trace the request and cleanup path through InfluxDB2/DefaultApi.php and WriteApi.php. Re-run repeated HTTPS connections while watching memory; done means certificate memory does not grow heavily and the certificate-file error no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.