PHP resource error, memory leak?
My LDAP import started failing about 3 days ago and is logging memory exhaustion even after increasing the max memory in my php config from 128m to 1024m. as soon as I start the import I can watch it load a ton of memory then crash, and nothing has changed over the last few weeks, why is this all the sudden an issue?
Please confirm you have done the following before posting your bug report:
- [x] I have enabled debug mode
- [x] I have read checked the Common Issues page
Please provide answers to these questions before posting your bug report:
-
Version of Snipe-IT you're running: 3.6.6 build 1
-
What OS and web server you're running Snipe-IT on: Server 2012 R2 IIS 8
-
What method you used to install Snipe-IT (install.sh, manual installation, docker, etc): install.sh
-
WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error: none
-
What specific Snipe-IT page you're on, and what specific element you're interacting with to trigger the error: ldap import
-
If a stacktrace is provided in the error, include that too.: none
-
Any errors that appear in your browser's error console.: none
-
Confirm whether the error is reproduceable on the demo.: n/a
-
Include any additional information you can find in
app/storage/logsand your webserver's logs.: [2017-09-13 15:22:49] production.ERROR: Symfony\Component\Debug\Exception\FatalErrorException: Allowed memory size of 524288000 bytes exhausted (tried to allocate 20480 bytes) in C:\inetpub\wwwroot\snipe-it\app\Models\Ldap.php:271 -
Include what you've done so far in the installation, and if you got any error messages along the way: increased max memory size thinking the import got too big, but 10X increase didn't fix it.
-
Indicate whether or not you've manually edited any data directly in the database: none
Just to test, I changes my max memory to -1 and reset the web server but it still crashed with the same error.
Can you check your fastCGI settings, in particular Instance MaxRequests, Max Instances & Activity Timeout
That memory error might actually be a red herring, i've had simliar issues in the past on Server 2008/IIS with a different Symfony app but can't remember exactly how I fixed it.
Currently my fastcgi settings are as followed,
Instance MaxRequests: 10000 Max Instances: 0 Activity Timeout: 600
I was able to identify that if I run an LDAP sync from within the web gui it runs successfully, so this error only seems to be an issue with running the import command from the command-line.
@snipe there's a hard coded memory limit (500M matching the error) located in the LdapSync function, so there's a pretty good chance this is it.
https://github.com/snipe/snipe-it/blob/develop/app/Console/Commands/LdapSync.php
@ericdude101 if you can try raise the limit in that file on your local copy to confirm?
That seems to have resolved the issue! Thank you very much!
Given it is possible to land at this page via searching for memory errors in LDAP sync, I'd like to note you can now increase the LDAP sync memory limit by setting the LDAP_MEM_LIMIT variable in Snipe-IT's .env file. It defaults to 500M.
Given it is possible to land at this page via searching for memory errors in LDAP sync, I'd like to note you can now increase the LDAP sync memory limit by setting the
LDAP_MEM_LIMITvariable in Snipe-IT's.envfile. It defaults to 500M.
I think it's important to correct this. The environment variable is currently not LDAP_MEM_LIMIT, it is LDAP_MEM_LIM. You can also change the execution timeout limit with the LDAP_TIME_LIM environment variable. The memory limit must be expressed as a string with M appended (for megabyte) and the time limit is just an integer representing time in seconds.
If anyone else comes across this post: the documentation for the Cron job is incomplete. You must set the environment variables manually, as the script from command line does not get the environment variables. export LDAP_MEM_LIM=2500M php artisan snipeit:ldap-sync