Endless loop if fallback device is missing

The API formerly known as Tera-WURFL
digitalronin
Posts: 13
Joined: Tue Jul 05, 2011 10:18 am

Endless loop if fallback device is missing

Postby digitalronin » Wed Nov 23, 2011 10:46 am

I have a patch file containing useragents that I see which are not in WURFL. These useragents are created by an app. running on the device, so they are only relevant to my own system, and hence not worth contributing to WURFL. Each of these "synthetic" useragents needs a unique WURFL ID, and a fallback ID pointing to a device which *is* in the main WURFL.

Unfortunately, devices are sometimes removed from wurfl.xml, e.g. motorola_xt502_ver1 disappeared between version 2.2 and 2.3

When this happens, and you try to recognise a device in the patch file whose fallback device is missing, you run into problems.

1. getDeviceFallBackTree in TeraWurflDatabase_MySQL5.php goes into an endless loop. This can be fixed by limiting the number of fallback attempts, like this;

diff --git a/libraries/terawurfl/DatabaseConnectors/TeraWurflDatabase_MySQL5.php b/libraries/terawurfl
index 5b7724c..9d47b28 100644
--- a/libraries/terawurfl/DatabaseConnectors/TeraWurflDatabase_MySQL5.php
+++ b/libraries/terawurfl/DatabaseConnectors/TeraWurflDatabase_MySQL5.php
@@ -144,8 +144,8 @@ class TeraWurflDatabase_MySQL5 extends TeraWurflDatabase{
$data[$i++]=unserialize($row[0]);
$res->free();
}
- }while($this->dbcon->more_results() && $this->dbcon->next_result());
- if($i == 0){
+ }while($i < 100 && $this->dbcon->more_results() && $this->dbcon->next_result());^M
+ if($i == 0 || $i >= 100){^M
$tw = new TeraWurfl();
$tw->toLog("Tera-WURFL Error: database fallback procedure returned no records,
}else if($data[$i-1]['id'] != WurflConstants::$GENERIC){

Once the endless loop is fixed, you get these errors;

E_RECOVERABLE_ERROR: Argument 1 passed to TeraWurfl::addCapabilities() must be an array, boolean given, called in terawurfl/TeraWurfl.php on line 343 and defined in terawurfl/TeraWurfl.php on line 483
E_RECOVERABLE_ERROR: Argument 2 passed to TeraWurfl::mergeCapabilities() must be an array, boolean given, called in terawurfl/TeraWurfl.php on line 484 and defined in terawurfl/TeraWurfl.php on line 499

These can be fixed by adding a line like this to TeraWurfl.php at line 342 in getFullCapabilities;

$dev = is_array($dev) ? $dev : array($dev);

Now that that is fixed, you get this error;

Unexpected exception of type [Exception] with message [Error: Commands out of sync; you can't run this command now] in [/home/vagrant/Adserver/libraries/terawurfl/DatabaseConnectors/TeraWurflDatabase_MySQL5.php line 375]

The root cause of this is having a null pointer in the wurfl data structure - a fallback device whose ID does not exist. Obviously, that shouldn't happen. But, the patch file system makes that perfectly possible, and the ad hoc way in which device IDs are pulled from wurfl.xml exacerbates the problem.

IMO, if you're going to be charging for wurfl and the the API as professional software products, I think you need to ship it with a decent regression test suite and implement some kind of change control/logging process, so that customers get some warning that the wurfl ID on which they had a dependency has now disappeared.

Regards

David

luca.passani
Posts: 65
Joined: Thu May 19, 2011 2:49 pm

Re: Endless loop if fallback device is missing

Postby luca.passani » Thu Nov 24, 2011 10:14 am

We have normalized the ID of the device to be more consistent:

http://db.scientiamobile.com/device/show/29115

btw, we have a product in our roadmap that will allow customers to manage their own patch files and keep them "in sync" with the big WURFL

Luca

kamermans
Posts: 393
Joined: Mon Jun 06, 2011 9:50 am

Re: Endless loop if fallback device is missing

Postby kamermans » Fri Nov 25, 2011 11:03 am

Thanks for the detailed information. The nonexistent fallback bug is fixed in the trunk - it definitely should not result in an endless loop, but rather throw an exception or return a very generic result. This update will be released in the coming weeks.
Thanks,

Steve Kamerman
ScientiaMobile

Make sure you check out our WURFL Cloud, WURFL InSight and WURFL InFuze products!


Who is online

Users browsing this forum: Bing [Bot] and 1 guest