Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98210 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 7196 invoked from network); 5 Feb 2017 18:18:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2017 18:18:18 -0000 Authentication-Results: pb1.pair.com header.from=andrey@andb.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=andrey@andb.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain andb.name designates 185.11.74.146 as permitted sender) X-PHP-List-Original-Sender: andrey@andb.name X-Host-Fingerprint: 185.11.74.146 andb.name Received: from [185.11.74.146] ([185.11.74.146:58626] helo=andb.name) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 21/21-30708-86C67985 for ; Sun, 05 Feb 2017 13:18:17 -0500 Received: from mail.andb.name (localhost [127.0.0.1]) by andb.name (Postfix) with ESMTPA id 1F17130094E; Sun, 5 Feb 2017 21:18:13 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.10.3 andb.name 1F17130094E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=andb.name; s=mail; t=1486318693; bh=/OungfLVEcBnWXHjgyP43L/xc9A44kzmy5CKRb7WqVM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=EdwNX1H97XbCHfAsBNMZVxOfDFgjx0ogCRQB4X22WaKYbOCJyyxhoLldg8BjwmL7i iv+WkKAKrb7dWOdahV69Onmn3DjE3ZPHd+bnRJ46uBac6WfupHnx0ZzWw3gcZlfa3/ P3YW4yu2MC1c79DVdaeSLcjNiTWvshzopaIhL/ZU= MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 06 Feb 2017 01:18:12 +0700 To: Nikita Popov Cc: internals , Laruence , alexvmesh@gmail.com, artyomnsk2012@gmail.com In-Reply-To: References: <48a7eb6950ea9a1f512937f138dd5fb9@andb.name> Message-ID: X-Sender: andrey@andb.name User-Agent: Roundcube Webmail/1.3-git Subject: Re: [PHP-DEV] Need help with strange and random bug From: andrey@andb.name (Andrey E Baranov) Nikita Popov at 2017-02-05 21:44 wrote: > On Sun, Feb 5, 2017 at 3:03 PM, Andrey E Baranov > wrote: > >> Hi all, >> >> I have problem, debug is not yet finished, and for now do not can >> reproduce, problem occurs only in production (after migrate to PHP7). >> perhaps someone else can help :) >> PHP 7.0.13 (Ubuntu 16.04 package repository), php-fpm >> >> For simplify: >> ``` >> ... >> Log::debug('1:' . print_r($video, true)); >> Log::debug('2:' . json_encode($video) . ' json_last_error: ' . >> json_last_error() . ' json_last_error_msg: ' . json_last_error_msg()); >> >> $video['delivery'] = [2]; // after this line: serialize and >> json_encode do >> not work as expected >> >> Log::debug('3:' . print_r($video, true)); >> Log::debug('4:' . serialize($video)); >> Log::debug('5:' . json_encode($video) . ' json_last_error: ' . >> json_last_error() . ' json_last_error_msg: ' . json_last_error_msg()); >> ... >> ``` >> >> log with bug: >> ``` >> DEBUG: 1:Array >> ( >> [mimes] => Array >> ( >> [0] => video/mp4 >> ) >> >> [linearity] => 1 >> [minduration] => 5 >> [maxduration] => 60 >> [protocols] => Array >> ( >> [0] => 2 >> [1] => 3 >> ) >> >> [w] => 818 >> [h] => 460 >> [minbitrate] => 100 >> [maxbitrate] => 1200 >> ) >> DEBUG: 2: {"mimes":["video/mp4"],"linearity":1,"minduration":5,"maxdur >> ation":60,"protocols":[2,3],"w":818,"h":460,"minbitrate": >> 100,"maxbitrate":1200} >> DEBUG: 3:Array >> ( >> [mimes] => Array >> ( >> [0] => video/mp4 >> ) >> >> [linearity] => 1 >> [minduration] => 5 >> [maxduration] => 60 >> [protocols] => Array >> ( >> [0] => 2 >> [1] => 3 >> ) >> >> [w] => 818 >> [h] => 460 >> [minbitrate] => 100 >> [maxbitrate] => 1200 >> [delivery] => Array >> ( >> [0] => 2 >> ) >> >> ) >> DEBUG: 4:a:10:{s:5:"mimes";a:1:{i:0;s:9:"video/mp4";}s:9:"linearity >> ";i:1;s:11:"minduration";i:5;s:11:"maxduration";i:60;s:9:"p >> rotocols";a:2:{i:0;i:2;i:1;i:3;}s:1:"w";i:818;s:1:"h";i:460; >> s:10:"minbitrate";i:100;s:10:"maxbitrate";i:1200;s:8:"delivery";N;} >> DEBUG: 5: json_last_error: 6 json_last_error_msg: Recursion detected >> ``` >> >> - 4: `serialize($video)` - `"delivery";N;` - it is mean that >> `delivery` is >> Null - that is not true >> - 5: `json_encode($video)` - Recursion detected >> >> Problem occurs in random period after start fpm process (after 10..30 >> min), and remains constant until restart fpm >> >> Same problem as I see in http://stackoverflow.com/quest >> ions/37456845/what-does-json-error-recursion-mean-from-json-encode >> >> After deep analyze: >> >> php_json_encode_array: >> ``` >> ``` >> if (myht && ZEND_HASH_GET_APPLY_COUNT(myht) > 1) { >> JSON_G(error_code) = PHP_JSON_ERROR_RECURSION; >> smart_str_appendl(buf, "null", 4); >> return; >> } >> ``` >> >> serialize: >> ``` >> if (... || (Z_TYPE_P(data) == IS_ARRAY && >> Z_ARRVAL_P(data)->u.v.nApplyCount >> > 1) >> ) { >> smart_str_appendl(buf, "N;", 2); >> ... >> ``` >> >> so looks like problem in `HashTable.v.nApplyCount` >> >> >> Also I am find commit - https://github.com/php/php-src >> /commit/d26ca894020bc28eb55b153fac5548374d5ce16d >> >> In this commit added >> ``` >> target->u.flags = (source->u.flags & >> ~(...|ZEND_HASH_APPLY_COUNT_MASK))... >> ``` >> But not added to case if `if (GC_FLAGS(source) & IS_ARRAY_IMMUTABLE)` >> - >> maybe need fix in this place? :) I guess that the problem in immutable >> arrays. >> > > The apply count on immutable arrays is always zero, so this shouldn't > be a > problem. However, it may be that some other code is incrementing the > apply > count on an immutable array. Can you please check whether running with > opcache.protect_memory=1 gives you any segmentation faults or bus > errors? > > Nikita Nikita thanks! looks like `opcache.protect_memory=1` is usefull :) ``` #0 phongo_bson_append (bson=bson@entry=0x7fff0d47e220, flags=flags@entry=PHONGO_BSON_NONE, key=0x7fabe79ec070 "$in", key_len=3, entry=entry@entry=0x7fabe7f79a00) at /tmp/pear/temp/mongodb/src/bson.c:1027 ... ``` and it is fixed in https://github.com/mongodb/mongo-php-driver/commit/129753881a223b8378fc7b8137104c65d8d8828f so, with PHP7 need use mongodb >= 1.1.10 (as minimum :) we missed that mongodb is outdated in our production, but the relationship between our bug and mongodb was not the obvious)