madhabkirank / google-api-adwords-php

Automatically exported from code.google.com/p/google-api-adwords-php
0 stars 0 forks source link

memory corruption (segfault or "zend_mm_heap corrupted") on various calls #20

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Which version of the library are you using?
 - have tried all downloadable versions of the library, including the trunk

Which version of PHP are you using?
 - 5.2.4

What steps will reproduce the problem?
 - create a campaign, get the campaign, delete it, get again

What is the expected output? What do you see instead?
 - expected: no segfault
 - actual: segfault or zend_mm_heap corrupted message

Please provide any additional information below.

Since we implemented v2009 we have been seeing some of our API calls 
terminate with "Segmentation fault" or "zend_mm_heap corrupted" messages, 
or various other messages indicating the memory is corrupt. This happens 
on various API calls on various types of objects, so it's not limited to 
just campaigns. However, for the sake of this bug report, I have a simple 
duplicateable instance of campaign create that causes the problem. 

Please note that if I run the same thing on a different server, I do not 
get a segfault in the same place, sometimes not at all, even though the 
software versions are exactly the same. This is probably due to different 
memory capacity/setup, so the corrupted memory doesn't get "hit" at the 
same time. 

First, we create the campaign:

=======================================================

SOAP::CampaignService::mutate() - params
CampaignServiceMutate Object
(
    [operations] => Array
        (
            [0] => CampaignOperation Object
                (
                    [biddingTransition] => 
                    [operand] => Campaign Object
                        (
                            [id] => 
                            [name] => 78359_Unit Test Campaign 2 2010-04-
09 3815667
                            [status] => ACTIVE
                            [servingStatus] => 
                            [startDate] => 
                            [endDate] => 20100509
                            [budget] => Budget Object
                                (
                                    [period] => DAILY
                                    [amount] => Money Object
                                        (
                                            [microAmount] => 20000000
                                            [ComparableValueType] => 
                                            [_parameterMap:private] => 
Array
                                                (
                                                    [ComparableValue.Type] 
=> ComparableValueType
                                                )

                                        )

                                    [deliveryMethod] => STANDARD
                                )

                            [biddingStrategy] => SoapVar Object
                                (
                                    [enc_type] => 301
                                    [enc_stype] => ManualCPC
                                    [enc_ns] => 
https://adwords.google.com/api/adwords/cm/v200909
                                )

                            [autoKeywordMatchingStatus] => 
                            [stats] => 
                            [adServingOptimizationStatus] => 
                            [frequencyCap] => 
                        )

                    [operator] => ADD
                    [OperationType] => 
                    [_parameterMap:private] => Array
                        (
                            [Operation.Type] => OperationType
                        )

                )

        )

)

=======================================================

Which succeeds. Then we set the targeting:

=======================================================

SOAP::CampaignTargetService::mutate() - params
CampaignTargetServiceMutate Object
(
    [operations] => Array
        (
            [0] => CampaignTargetOperation Object
                (
                    [operand] => SoapVar Object
                        (
                            [enc_type] => 301
                            [enc_value] => GeoTargetList Object
                                (
                                    [targets] => 
                                    [campaignId] => 49005872
                                    [TargetListType] => 
                                    [_parameterMap:private] => Array
                                        (
                                            [TargetList.Type] => 
TargetListType
                                        )

                                )

                            [enc_stype] => GeoTargetList
                            [enc_ns] => 
https://adwords.google.com/api/adwords/cm/v200909
                        )

                    [operator] => SET
                    [OperationType] => 
                    [_parameterMap:private] => Array
                        (
                            [Operation.Type] => OperationType
                        )

                )

            [1] => CampaignTargetOperation Object
                (
                    [operand] => SoapVar Object
                        (
                            [enc_type] => 301
                            [enc_value] => GeoTargetList Object
                                (
                                    [targets] => Array
                                        (
                                            [0] => NetworkTarget Object
                                                (
                                                    [networkCoverageType] 
=> GOOGLE_SEARCH
                                                    [TargetType] => 

[_parameterMap:private] => Array
                                                        (
                                                            [Target.Type] 
=> TargetType
                                                        )

                                                )

                                            [1] => NetworkTarget Object
                                                (
                                                    [networkCoverageType] 
=> SEARCH_NETWORK
                                                    [TargetType] => 

[_parameterMap:private] => Array
                                                        (
                                                            [Target.Type] 
=> TargetType
                                                        )

                                                )

                                        )

                                    [campaignId] => 49005872
                                    [TargetListType] => 
                                    [_parameterMap:private] => Array
                                        (
                                            [TargetList.Type] => 
TargetListType
                                        )

                                )

                            [enc_stype] => NetworkTargetList
                            [enc_ns] => 
https://adwords.google.com/api/adwords/cm/v200909
                        )

                    [operator] => SET
                    [OperationType] => 
                    [_parameterMap:private] => Array
                        (
                            [Operation.Type] => OperationType
                        )

                )

        )

)

=======================================================

Which also succeeds. Next we make a call to get the campaign:

=======================================================

SOAP::CampaignService::get() - params
CampaignServiceGet Object
(
    [selector] => CampaignSelector Object
        (
            [ids] => Array
                (
                    [0] => 49005872
                )

            [campaignStatuses] => Array
                (
                    [0] => ACTIVE
                    [1] => PAUSED
                )

            [statsSelector] => 
            [paging] => Paging Object
                (
                    [startIndex] => 0
                    [numberResults] => 10000
                )

        )

)

=======================================================

And grab the targeting:

=======================================================

SOAP::CampaignTargetService::get() - params
CampaignTargetServiceGet Object
(
    [selector] => CampaignTargetSelector Object
        (
            [campaignIds] => 49005872
        )

)

=======================================================

Also succeeds. In our test case we then delete the campaign:

=======================================================

SOAP::CampaignService::mutate() - params
CampaignServiceMutate Object
(
    [operations] => Array
        (
            [0] => CampaignOperation Object
                (
                    [biddingTransition] => 
                    [operand] => Campaign Object
                        (
                            [id] => 49005872
                            [name] => 78359_Unit Test Campaign 2 2010-04-
09 3815667
                            [status] => DELETED
                            [servingStatus] => 
                            [startDate] => 
                            [endDate] => 20100509
                            [budget] => Budget Object
                                (
                                    [period] => DAILY
                                    [amount] => Money Object
                                        (
                                            [microAmount] => 20000000
                                            [ComparableValueType] => 
                                            [_parameterMap:private] => 
Array
                                                (
                                                    [ComparableValue.Type] 
=> ComparableValueType
                                                )

                                        )

                                    [deliveryMethod] => STANDARD
                                )

                            [biddingStrategy] => 
                            [autoKeywordMatchingStatus] => 
                            [stats] => 
                            [adServingOptimizationStatus] => 
                            [frequencyCap] => 
                        )

                    [operator] => SET
                    [OperationType] => 
                    [_parameterMap:private] => Array
                        (
                            [Operation.Type] => OperationType
                        )

                )

        )

)

=======================================================

If we perform another call after this point, the process will
segfault somewhere in the SOAP extension, sometimes with a "Segmentation 
fault" message, other times with a "zend_mm_heap corrupted" message. 

In this case, we'll just perform another get() on the campaign id
we have been using:

=======================================================

SOAP::CampaignService::get() - params
CampaignServiceGet Object
(
    [selector] => CampaignSelector Object
        (
            [ids] => Array
                (
                    [0] => 49005872
                )

            [campaignStatuses] => Array
                (
                    [0] => ACTIVE
                    [1] => PAUSED
                )

            [statsSelector] => 
            [paging] => Paging Object
                (
                    [startIndex] => 0
                    [numberResults] => 10000
                )

        )

)

=======================================================

Result: process terminates with "zend_mm_heap corrupted" message
We're speculating that the memory corruption occurs sometime before the 
last API call, but we don't hit the corrupt memory until then, causing the 
fault. 

Have we incorrectly packaged the campaign object somewhere, or is there 
something else you notice?

Let me reiterate that we are getting segfaults on various calls on various 
types of objects (including keywords, ads, groups, etc.). 

I'd be happy to provide more information, just let me know what you need.

Original issue reported on code.google.com by bly...@adobe.com on 9 Apr 2010 at 12:57

GoogleCodeExporter commented 8 years ago
I can confirm a similar behavior which seem to occur randomly. I think it might 
be
related to a known problem with Suhosin which detects some sort of memory 
corruption.

Original comment by ckr...@klicktel.de on 9 Apr 2010 at 1:48

GoogleCodeExporter commented 8 years ago
Thanks for confirming the issue, however we do not have Suhosin...

Original comment by bly...@adobe.com on 9 Apr 2010 at 3:46

GoogleCodeExporter commented 8 years ago
Hi blyman,

Can you post some of the sample code you used to make these requests?  I'm 
having 
trouble replicating the structure of your arguments exactly.

I've been able to get some seg faults with php 5.2.4, although for me it's 
happening 
when trying to create a Campaign.  I've found that I can include a 
biddingStrategy or 
a budget amount without it crashing, but once I include both it seg faults.  
I've 
done some mild gdb analysis of the core files, and it looks like the problem is 
contained in the SoapClient class, which the library extends.

I ran some tests using PHP 5.2.5, and everything worked perfectly.  I'll do 
some more 
testing, but it could be that the SOAP extension isn't stable enough in PHP 
5.2.4 
(and earlier) to rely on.

Original comment by api.ekol...@gmail.com on 9 Apr 2010 at 3:51

GoogleCodeExporter commented 8 years ago
Thanks for your response. From what I understand it's very hard to get our org 
to 
upgrade PHP versions for our product because there's a lot of planning and 
infrastructure that has to be in place. So the ideal would be to solve the 
problem 
without doing so if at all possible. 

Here are the functions we use for packaging the campaign into soap objects. 
Please 
let me know if there's something else I can provide.

=============================================

    function packageSECampaignForSearchEngine($campaign) {
        $arrChangeList = explode(',', $campaign->getChangeList());
        $row = $campaign->getRow();

        // Create operations.
        $operation = new CampaignOperation();

        //the google api campaign object.  I wonder if we should name space 
it.
        $requestCampaign = new Campaign();

        //-- The campaign name
        if(true == in_array('name', $arrChangeList)) $requestCampaign->name 
= $row['name'];

        //-- The daily budget
        if(true == in_array('budget', $arrChangeList)) {
            $budget = new Budget();
            $budget->period = strtoupper($row['budget_period']);
            $budget->amount = new Money((float)
SCM_SearchEngineGoogle::currencyToGoogle($row['budget']));
            $budget->deliveryMethod = ('Accelerated' == $row
['budget_delivery']) ? ACCELERATED : STANDARD;
            $requestCampaign->budget = $budget;
        }

        $biddingStrategyType = (SCM_SearchCenterGoogle::COST_TYPE_CPM == 
$campaign->getCostType()) ? 'ManualCPM' : 'ManualCPC';
        //when creating a new campaign we must include the biddingStrategy
        if(!$campaign->getSEId()){
            $operation->operator = 'ADD';
            //Google want the deliveryMethod to xml to have an xsi:type 
attribute of the biddingStrategy instead of a value
            $requestCampaign->biddingStrategy = new SoapVar(null, 
SOAP_ENC_OBJECT, $biddingStrategyType, GOOGLE_REQUEST_NAMESPACE_V200909);
        }else{
            $operation->operator = 'SET';
            //-- The remote engine id
            $requestCampaign->id = (float)$campaign->getSEId();

            if(true == in_array('cost_type', $arrChangeList)) { 
                $biddingTransition = new 
ConversionOptimizerBiddingTransition();
                $biddingTransition->targetBiddingStrategy = new 
SoapVar(null, SOAP_ENC_OBJECT, $biddingStrategyType, 
GOOGLE_REQUEST_NAMESPACE_V200909);

                $newMaxCpm = $campaign->getMaxCpm();
                $newKeywordMaxCpc = $campaign->getKeywordMaxCpc();
                $newKeywordContentMaxCpc = $campaign-
>getKeywordContentMaxCpc();
                $newSiteMaxCpc = $campaign->getSiteMaxCpc();

                switch($biddingStrategyType){
                    case 'ManualCPM':
                        $bids = new ManualCPMAdGroupBids();
                        $bidType = 'ManualCPMAdGroupBids';
                        $bids->maxCpm->amount = new Money
((float)SCM_SearchEngineGoogle::currencyToGoogle($newMaxCpm));
                        break;
                    case 'ManualCPC':
                        $bids = new ManualCPCAdGroupBids();
                        $bidType = 'ManualCPCAdGroupBids';
                        $bids->keywordMaxCpc->amount = new 
Money((float)SCM_SearchEngineGoogle::currencyToGoogle($newKeywordMaxCpc));
                        $bids->keywordContentMaxCpc->amount 
= new Money((float)SCM_SearchEngineGoogle::currencyToGoogle
($newKeywordContentMaxCpc));
                        $bids->siteMaxCpc->amount = new Money
((float)SCM_SearchEngineGoogle::currencyToGoogle($newSiteMaxCpc));
                        break;
                }

                $biddingTransition->explicitAdGroupBids = new SoapVar
($bids, SOAP_ENC_OBJECT, $bidType, GOOGLE_REQUEST_NAMESPACE_V200909);
                $operation->biddingTransition = $biddingTransition;
            }
        }

        if(true == in_array('status', $arrChangeList) || true == in_array
('deleted', $arrChangeList)) {  
            if ($campaign->getDeleted()) {
                $requestCampaign->status = 'DELETED';
            } else {
                $requestCampaign->status = ($row
['status'] ? 'ACTIVE' : 'PAUSED');
            }
        }

        //-- Do we have a start date and is it in the future
        if(true == in_array('start_date', $arrChangeList)) {    
            if ($row['start_date'] && $row['start_date'] > date('Y-m-
d')) {
                $requestCampaign->startDate = date('Ymd', strtotime
($row['start_date']));
            }
        }
        ///-- Do we have an end date, is it in the future and is it prior to 
Google's defined end date
        if(true == in_array('end_date', $arrChangeList)) {  
            if ($row['end_date'] && $row['end_date'] > date('Y-m-d') && 
$row['end_date'] < '2036-12-31') {
                $requestCampaign->endDate = date('Ymd', strtotime
($row['end_date']));
            }
        }
        //$requestCampaign->budgetOptimizerSettings=array
('bidCeiling'=>null,'enabled'=>'null','takeOnOptimizeBids'=>null);

        $operation->operand = $requestCampaign;

        return $operation;
    }

    function packageSECampaignTargetingForSearchEngine($campaign){
        $arrOperations = array();

        //target languages
        if(true == $campaign->hasTargetLanguageChange()){
            $targetListData = new LanguageTargetList();

            $targetListData->campaignId = (float)$campaign->getSEId();
            $targetListData->targets = array();

            $arrLanguages = explode("|",$campaign->getTargetLanguages());
            foreach($arrLanguages as $strLanguageCode){
                if(false == empty($strLanguageCode)) $targetListData-
>targets[] = new LanguageTarget($strLanguageCode);
            }

            $targetList = new SoapVar($targetListData, 
SOAP_ENC_OBJECT, 'LanguageTargetList', GOOGLE_REQUEST_NAMESPACE_V200909);

            $operation = new CampaignTargetOperation();
            $operation->operand = $targetList;
            $operation->operator = 'SET';

            $arrOperations[] = $operation;
        }

        //geo target list
        if(true == $campaign->getTargetLocationsAllow() && true == $campaign-
>hasTargetLocationChange()){
            $targetListData = new GeoTargetList();
            $targetListData->campaignId = (float)$campaign->getSEId();

            $arrGeoTargets = explode("@", $campaign->getTargetLocations
());
            foreach($arrGeoTargets as $typeTargets){
                $arrTypeTargets = explode("|", $typeTargets);
                $targetType = array_shift($arrTypeTargets);
                foreach ($arrTypeTargets as $specificType){
                    switch($targetType){
                        case "countries":
                            $countryTarget = new 
CountryTarget();
                            $countryTarget->countryCode 
= $specificType;
                            $targetListData->targets[] = 
new SoapVar($countryTarget, SOAP_ENC_OBJECT, 'CountryTarget', 
GOOGLE_REQUEST_NAMESPACE_V200909);
                            break;
                        case "areas":
                            $metroTarget = new 
MetroTarget();
                            $metroTarget->metroCode = 
$specificType;
                            $targetListData->targets[] = 
new SoapVar($metroTarget, SOAP_ENC_OBJECT, 'MetroTarget', 
GOOGLE_REQUEST_NAMESPACE_V200909);
                            break;
                        case "cities":
                            list($cityName, $other) = 
explode(", ", $specificType); 
                            $arrCityTargets = explode
(" ", $other);

                            $cityTarget = new CityTarget
();
                            $cityTarget->cityName = trim
(str_replace(",","",$cityName));
                            $cityTarget->provinceCode = 
trim($arrCityTargets[1]) . "-" . trim($arrCityTargets[0]);
                            $cityTarget->countryCode = 
trim($arrCityTargets[1]);

                            $targetListData->targets[] = 
new SoapVar($cityTarget, SOAP_ENC_OBJECT, 'CityTarget', 
GOOGLE_REQUEST_NAMESPACE_V200909);
                            break;
                        case "regions":
                            $provinceTarget = new 
ProvinceTarget();
                            $provinceTarget-
>provinceCode = $specificType;

                            $targetListData->targets[] = 
new SoapVar($provinceTarget, SOAP_ENC_OBJECT, 'ProvinceTarget', 
GOOGLE_REQUEST_NAMESPACE_V200909);
                            break;
                    }
                }
            }
            $targetList = new SoapVar($targetListData, 
SOAP_ENC_OBJECT, 'GeoTargetList', GOOGLE_REQUEST_NAMESPACE_V200909);

            $operation = new CampaignTargetOperation();
            $operation->operand = $targetList;
            $operation->operator = 'SET';

            $arrOperations[] = $operation;
        }

        //target networks
        if(true == $campaign->hasTargetNetworkChange()){
            $targetListData = new NetworkTargetList();
            $targetListData->campaignId = (float)$campaign->getSEId();

            $arrNetworks = explode(",",$campaign->getTargetNetworks());
            foreach($arrNetworks as $strNetworkCode){
                $targetListData->targets[] = new NetworkTarget
($strNetworkCode);
            }

            $targetList = new SoapVar($targetListData, 
SOAP_ENC_OBJECT, 'NetworkTargetList', GOOGLE_REQUEST_NAMESPACE_V200909);

            $operation = new CampaignTargetOperation();
            $operation->operand = $targetList;
            $operation->operator = 'SET';

            $arrOperations[] = $operation;
        }   

        return $arrOperations;
    }

Original comment by bly...@adobe.com on 9 Apr 2010 at 6:43

GoogleCodeExporter commented 8 years ago
Hi,
I got the same problem with targetingIdeaService; I solve using a 32-bit 
system, instead of 64-bit.

Bye

Original comment by ferrante...@gmail.com on 24 Aug 2010 at 9:13

GoogleCodeExporter commented 8 years ago
I'm not able to reproduce this problem.

Original comment by api.ekol...@gmail.com on 15 Sep 2010 at 9:23