Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory leak and errors #149

Closed
gabrieleolmi opened this issue Jul 16, 2022 · 14 comments
Closed

memory leak and errors #149

gabrieleolmi opened this issue Jul 16, 2022 · 14 comments

Comments

@gabrieleolmi
Copy link

I have a server running Ubuntu 22.04 where I have apache and php installed. I have recently started using libvips for php, and I have noticed that every time a php script is run, the amount of ram used increases more and more, without being freed. I am forced to use Vips\Config::shutDown() at the end of the script otherwise the server ram gets saturated. I tried to use Vips\Config::cacheSetMax(5) but nothing changes (memory grows more and more).

php file example:

<?php
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;

$image = Vips\Image::newFromFile($inputImagePath);
//some operations on the width and height of the image
//.....
$image = Vips\Image::thumbnail($inputImagePath, $width, ['height' => $height, 'crop' => 'centre']);
$image->writeToFile($outputImagePath, ['Q' => $quality]);

Also sometimes libvips returns an error:

(process:211949): GLib-GObject-WARNING **: 16:54:47.542: cannot register existing type 'VipsObject'
(process:211949): GLib-CRITICAL **: 16:54:47.542: g_once_init_leave: assertion 'result != 0' failed
(process:211949): GLib-GObject-CRITICAL **: 16:54:47.542: g_type_register_static: assertion 'parent_
type > 0' failed
(process:211949): GLib-CRITICAL **: 16:54:47.542: g_once_init_leave: assertion 'result != 0' failed

libvips42 version: 8.12.1
php-vips version: 2.0.3

@jcupitt
Copy link
Member

jcupitt commented Jul 16, 2022

Hi @gabrieleolmi,

How is apache set up? I suppose you have fastcgi and a persistent process for requests, is that right?

@gabrieleolmi
Copy link
Author

FPM/FastCGI

@kleisauke
Copy link
Member

Perhaps this is a symptom of https://www.php.net/manual/en/language.oop5.decon.php#105368? I tried to debug that using commit kleisauke@d20ec0d and see about 45 references still alive after the OK print on the test suite.

@jcupitt
Copy link
Member

jcupitt commented Jul 18, 2022

Huh that's a bit surprising, there shouldn't be any circular references.

Does adding gc_collect_cycles() to your php fix this?

@kleisauke
Copy link
Member

Ah, my bad. You're right, there shouldn't be any circular references. Commit kleisauke@73d05c0 fixes that, it seems we need to explicitly unset the images in tearDown() (just like teardown_class in libvips' test suite).

@kleisauke
Copy link
Member

The cannot register existing type error can probably be fixed if libvips is linked with -Wl,-z,nodelete, see: #142 (comment)

Hopefully that would also fix the memory leak you were seeing.

@jcupitt
Copy link
Member

jcupitt commented Jul 23, 2022

@gabrieleolmi libvips 8.13 is out now with Kleis's linking improvement (setting nodelete).

https://github.com/libvips/libvips/releases

Any testing would be great.

@gabrieleolmi

This comment was marked as resolved.

@gabrieleolmi
Copy link
Author

The cannot register existing type error can probably be fixed if libvips is linked with -Wl,-z,nodelete, see: #142 (comment)

Hopefully that would also fix the memory leak you were seeing.

I built libvips 8.13 from source and i did some quick tests. Vips\Config::cacheSetMax() seems to work and no more GLib errors appear 😀.

@jcupitt
Copy link
Member

jcupitt commented Jul 23, 2022

Woo! Great, thank you for doing the testing.

@jcupitt jcupitt closed this as completed Jul 23, 2022
@gabrieleolmi
Copy link
Author

Errors when calling Vips\Config::shutDown();

[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.461: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.461: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.462: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.462: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.462: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.462: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.462: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.463: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.463: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.463: g_hash_table_insert_internal: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 said into stderr: "(process:89482): GLib-CRITICAL **: 23:02:06.463: g_hash_table_lookup: assertion 'hash_table != NULL' failed"
[23-Jul-2022 23:02:06] WARNING: [pool www] child 89482 exited on signal 11 (SIGSEGV - core dumped) after 166.434485 seconds from start
[23-Jul-2022 23:02:06] NOTICE: [pool www] child 90288 started

@jcupitt
Copy link
Member

jcupitt commented Jul 23, 2022

You can't use libvips again after shutdown, and you can't init again. Only call it just before process exit.

@gabrieleolmi
Copy link
Author

I called Vips\Config::shutDown(); at the end of the script. So i think it's the fastcgi process that keeps running.

@jcupitt
Copy link
Member

jcupitt commented Jul 24, 2022

Yes, fastcgi is a persistent process, Don't call shutdown if you use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants