[ZBX-5735] 500 Internal Server Error (RestClient::InternalServerError) Created: 2012 Oct 25  Updated: 2017 May 30  Resolved: 2013 Oct 08

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: API (A)
Affects Version/s: 2.0.4rc1
Fix Version/s: 2.0.10rc1

Type: Incident report Priority: Minor
Reporter: Jesus Orosco Assignee: Ivo Kurzemnieks
Resolution: Fixed Votes: 2
Labels: limits, memory, patch, php, trivial
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 12 - Apache 2.2.22 - PHP - 5.3.10 - Mysql 5.5.24


Attachments: File import_w_templateId.json     File import_wo_templateId.json     File zabbix_debug.tiff    
Issue Links:
Duplicate
duplicates ZBX-5400 PHP memory leak while importing(updat... Closed

 Description   

I am using the API to create hosts on my test zabbix server. I can successfully add eight hosts without any problems, that is until I try to add a templateid tag. With the templateId in place I am getting the following error:

500 Internal Server Error (RestClient::InternalServerError)

When I look at my apache web server logs I see the following:

[Wed Oct 24 17:35:21 2012] [error] [client 192.168.69.38] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 77 bytes) in /var/www/zabbix2/include/classes/debug/CProfiler.php on line 232

I have tried to increase the memory_limit alloted to PHP and only a slight change in the logs:

[Mon Oct 22 11:49:40 2012] [error] [client 192.168.69.38] PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 32 bytes) in /var/www/zabbix2/include/classes/debug/CProfiler.php on line 232

If I remove the templateid tag everything works as expected.



 Comments   
Comment by Oleksii Zagorskyi [ 2012 Oct 25 ]

we had similar problem here ZBX-5006

maybe you could try to increase the limit even more ?

How many new items/triggers/graphs should be created when you use templateid tag ?
Export please that template to XML and attach here.

Comment by Jesus Orosco [ 2012 Oct 25 ]

Hello,

Thank you for the response. In fact in my lab environment I have already dialed it up towards 2 gb and still no success. In production this won't be possible, though I am certain it's set at higher than the default 128mb.

Attached please find the Json files that I am generating and subsequently posting. One has the templateid and doesn't work, the other does not and does work.

Please understand that I put a print statement just before I do my post so the packages I am sending actually contain the leading and trailing "host.login" and "host.logout".

Thanks for your response.

Comment by Jesus Orosco [ 2012 Oct 25 ]

JSON post files, 1 with templateid and 1 without. Without works, with blows things up.

Comment by Alexei Vladishev [ 2012 Nov 07 ]

Well, I think it happens because of enabled debug mode for the user. It generates tons of debug messages and it obviously requires RAM.

Comment by Jesus Orosco [ 2012 Nov 07 ]

I wish it were that easy to explain, unfortunately not. I am using a plain version of Zabbix for my lab so if it doesn't come set by default I didn't change it. Having said that I confirm that the user I am using, typical "admin" with default password, does not have debug mode turned on. Please see attached screenshot.

Thanks,

Jesus

Comment by Jesus Orosco [ 2012 Nov 07 ]

No debug for user enabled.

Comment by Axel Wienberg [ 2013 May 28 ]

same problem here, installed zabbix out of the box, admin user does not have debug enabled, but profileSql still causes memory overflow during api call. It seems the code assumes that if 'debug_mode' is not set (which is the case during an API call), then debugging should be turned on.

After exchanging the following lines in /usr/share/zabbix/include/classes/debug/CProfiler.php (occurs 2 times), things worked for me:

does not work:

  if ((!is_null($USER_DETAILS) && isset($USER_DETAILS['debug_mode']) && ($USER_DETAILS['debug_mode'] == GROUP_DEBUG_MODE_DISABLED))) {

works:

  if ((!is_null($USER_DETAILS) && (!isset($USER_DETAILS['debug_mode']) || ($USER_DETAILS['debug_mode'] == GROUP_DEBUG_MODE_DISABLED)))) {
Comment by Alexei Vladishev [ 2013 Jul 18 ]

Thanks for the patch, we should fix it asap.

Comment by Ivo Kurzemnieks [ 2013 Oct 08 ]

Adding a template to host performs around additional 748 queries (941 for v2.0) for each host depending on template size.
If debug mode is enabled, each querie is stored in array. The array data gets too big and PHP runs out of memory.

In 2.2 there are initial 8 queries in the beginning. Those alose queries are no longer taken into account. Same debug mode check condition now also applies to API call data storage.
RESOLVED in svn://svn.zabbix.com/branches/dev/ZBX-5735

In 2.0 "debug_mode" parameter wasn't passed to a global variable, so the condition didn't work at all.
Condition for debug mode check should now work correctly. The initial queries are also no longer taken into account. Same debug mode check condition now also applies to API call data storage.
RESOLVED in svn://svn.zabbix.com/branches/dev/ZBX-5735-2.0

Comment by Pavels Jelisejevs (Inactive) [ 2013 Oct 08 ]

(1) The initial DB queries should be always logged, as we discussed.

iivs RESOLVED for 2.0 in svn://svn.zabbix.com/branches/dev/ZBX-5735-2.0 r39105
Trunk dev branch removed since it was no longer necessary.

jelisejev Please correct the coding style: the expression contains extra parenthesis and we don't use is_null().

iivs RESOLVED in r39111

Comment by Pavels Jelisejevs (Inactive) [ 2013 Oct 09 ]

TESTED.

Comment by Ivo Kurzemnieks [ 2013 Oct 09 ]

Fixed in pre-2.0.10rc1 r39143

Generated at Sat Apr 20 11:48:27 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.