Comment On The Never Ending Error

If your application is going to fail, you may as well have it do so in a spectacular fashion. Sure, you could just display a simple error message and be done with it, but that's no fun; it's much better to just ruin the system for everyone else. At least, that's how the users of Niall's newly inherited system believed it was designed. The previous maintenance developer just got accustomed to rebooting the server several times whenever the application froze and told the users there was nothing he could do, because there was nothing in the logs to say why it failed. Niall, instead, decided to take a peek at the code ... [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: The Never Ending Error

2006-05-09 12:20 • by Joshua
Brillant new error handling approach!

do {
LogError();
} while (true);

Re: The Never Ending Error

2006-05-09 12:21 • by ammoQ
This kind of bug happens more often than we think. I've recently seen a similar bug, thought not in a infinite loop fashion.

Re: The Never Ending Error

2006-05-09 12:22 • by Colin
Hardly a WTF at all.  Slap a check for if not connected then log with error_log() or just bail.



An oversight like this isn't a WTF, sheesh.

Re: The Never Ending Error

2006-05-09 12:26 • by HopHead
71909 in reply to 71908

>>An oversight like this isn't a WTF, sheesh.


The WTF isn't the code. The WTF is that the previous maintenance developer didn't investigate and just rebooted the server any time there was an error that triggered the error trap infinite loop.


 


 

Re: The Never Ending Error

2006-05-09 12:36 • by X-Phile
Yes, when the phonelines go dead, I quickly get on the phone to call the phone company to let them know.

He must have left the position to move on to management.

Re: The Never Ending Error

2006-05-09 12:38 • by Joshua
The REAL WTF is the eventual stack overflow. That's what my do loop fixes!

Re: The Never Ending Error

2006-05-09 12:39 • by tiro
71913 in reply to 71908
Anonymous:
Hardly a WTF at all.  Slap a check for if not connected then log with error_log() or just bail.



An oversight like this isn't a WTF, sheesh.


Actually an oversight, leading to an infinite loop thereby crashing your entire program, sounds pretty much like the definition of a WTF.

Not saying I have never done it, that I will at least admit it.

Re: The Never Ending Error

2006-05-09 12:40 • by check that code again
71914 in reply to 71909
the code is also a WTF, because the query executed in the executeQuery function is using $sqlText to execute the query, not the parameter $string. Thus when the error occurs, it will continually execute the same query that caused the error instead of executing the error query.


Re: The Never Ending Error

2006-05-09 12:40 • by loneprogrammer
71915 in reply to 71908
Anonymous:
Hardly a WTF at all.  Slap a check for if not connected then log with error_log() or just bail.



An oversight like this isn't a WTF, sheesh.

You seem to have missed the point -- when the database goes down, how will you be able to write a log entry into a table in the very same database that just went down?

Re: The Never Ending Error

2006-05-09 12:41 • by Cooper
71916 in reply to 71909
Anonymous:

>>An oversight like this isn't a WTF, sheesh.




The WTF isn't the code. The WTF is that the previous maintenance developer didn't investigate and just rebooted the server any time there was an error that triggered the error trap infinite loop.



That is not a WTF - it is petty incompetence entrained into a support person by our Microsoft-PC environment.

A WTF is when something is done that rises above the level of normal laziness, incompetence,  ignorance, attitude or a combination.

This is not brillant, has no juice and isNotSortOfNull.

In an era of Uncle-Bill-induced reboot-for-memory-leaks, it is the normal learned activity for anybody not supervized by a manager willing to slap the developer/support person/whoever/whatever for not investigating.

Good people - the criteria for acceptance as a WTF is going south in a hurry.

Re: The Never Ending Error

2006-05-09 12:41 • by dhromed
71917 in reply to 71912
I guess this was written by a programmer who knew he was going to be fired, and he wanted some closure.

Re: The Never Ending Error

2006-05-09 12:42 • by Tim
71918 in reply to 71914
It also happens to be missing a single quote after the owner

Re: The Never Ending Error

2006-05-09 12:43 • by Mike5
71919 in reply to 71917
Keyboard not found! Press any key to continue...

also

2006-05-09 12:43 • by 'hook
71920 in reply to 71913

doesn't executeQuery() only take one argument anyway?

Re: The Never Ending Error

2006-05-09 12:49 • by Bus Raker
71921 in reply to 71909
Anonymous:

The WTF isn't the code. The WTF is that the previous maintenance developer didn't investigate and just rebooted the server any time there was an error that triggered the error trap infinite loop.



He could have just coded the shutdown right in the error handling ... it would have been much easier that way and he would have had more time to adjust his fantasy baseball lineup.

Re: The Never Ending Error

2006-05-09 12:53 • by Bus Raker
71923 in reply to 71913

tiro:
Anonymous:
Hardly a WTF at all.  Slap a check for if not connected then log with error_log() or just bail.

An oversight like this isn't a WTF, sheesh.


Actually an oversight, leading to an infinite loop thereby crashing your entire program, sounds pretty much like the definition of a WTF.

Not saying I have never done it, that I will at least admit it.


Yeah I ran into one that had a CheckUser() function in the HandleError() (so you could insert the user name into the log).  Of course the CheckUser() function also had an error handler that led to the HandleError() function .... similar results.  Talk about a stack overflow

Re: The Never Ending Error

2006-05-09 12:54 • by Zygo Blaxell
71924 in reply to 71914
Anonymous:
the code is also a WTF, because the query
executed in the executeQuery function is using $sqlText to execute the
query, not the parameter $string. Thus when the error occurs, it will
continually execute the same query that caused the error instead of
executing the error query.






Almost...it's the other way around.  Instead of executing the
offending command, it executes some random sql query.  One of the
possible sql queries it could be executing is the query that writes a
log message.



It's also odd that writeErrorToLog gives two arguments to executeQuery but executeQuery seems to need only one...

Re: The Never Ending Error

2006-05-09 12:56 • by wkapri

 $sqlText =
"INSERT INTO errorLog (ownerID,time,description,script) " .
"VALUES ('" . $owner . ",Now(),'" . $description . "','" . $script . "')";

isn't an apostrophe missing?


 "INSERT INTO errorLog (ownerID,time,description,script) " .
"VALUES ('" . $owner . "',Now(),'" . $description . "','" . $script . "')";

Re: The Never Ending Error

2006-05-09 13:12 • by Hilarious
71928 in reply to 71916
Cooper:
That is not a WTF - it is petty incompetence entrained into a support person by our Microsoft-PC environment.

A WTF is when something is done that rises above the level of normal laziness, incompetence,  ignorance, attitude or a combination.

This is not brillant, has no juice and isNotSortOfNull.


I'll agree this is pretty much incompetence, and not really crazy enough.

However, it was the first one in a long time that actually made me laugh out loud when I read the code.  (the truly brillant ones usually make me cry, rather than laugh)



Re: The Never Ending Error

2006-05-09 13:23 • by AASoft

hey, thats exactly what our system did untill not so long ago....and it was a web application too.


lol, i dont even have an account here, but just had to comment on that.

Re: The Never Ending Error

2006-05-09 13:28 • by It's a Feature
71930 in reply to 71908

Anonymous:
Hardly a WTF at all.  Slap a check for if not connected then log with error_log() or just bail.

An oversight like this isn't a WTF, sheesh.


 


You missed it.


 


The code follows this logic:


write data to database, if fail then call the write error to log routine, which calls the write data to database routine to write the error to the log.


 


It's called an infinite loop.

Re: The Never Ending Error

2006-05-09 13:31 • by jspenguin

Re: The Never Ending Error

2006-05-09 13:33 • by Arne
How often does your MySQL server fail right in the middle of script execution? He could have added a different error handler for when mysql_connect() fails and with the above code he wants to log any queries that might fail for whatever reason.
However, there must have been some error in copying this code for this thread, because mysql_query() will never execute something since the query is contained in $string and not $sqltext, thus it will always log an error.

Re: The Never Ending Error

2006-05-09 13:33 • by jimolina
71934 in reply to 71930

...or a recursive call...


--Jim

Re: The Never Ending Error

2006-05-09 13:35 • by Oscar L
71935 in reply to 71915

loneprogrammer:
Anonymous:
Hardly a WTF at all.  Slap a check for if not connected then log with error_log() or just bail.

An oversight like this isn't a WTF, sheesh.

You seem to have missed the point -- when the database goes down, how will you be able to write a log entry into a table in the very same database that just went down?


You'd be surprised.  I have errors try to log to the database first before falling back, and occasionally I get an error *in the database log* saying the database is unavailable.  It's good for a laugh every now and then.

Re: The Never Ending Error

2006-05-09 13:39 • by JudoPolecat
71936 in reply to 71926
Anonymous:

 $sqlText =
"INSERT INTO errorLog (ownerID,time,description,script) " .
"VALUES ('" . $owner . ",Now(),'" . $description . "','" . $script . "')";

isn't an apostrophe missing?


 "INSERT INTO errorLog (ownerID,time,description,script) " .
"VALUES ('" . $owner . "',Now(),'" . $description . "','" . $script . "')";

Actually, you're on to something...  executeQuery might fail for reasons other than connectivity, so it's not a WTF to log an error to the database.  The WTF is that the code that logged an error to the database was not well-tested, and not robust.  If anything should be robust, it should be your error-handling...

Re: The Never Ending Error

2006-05-09 13:44 • by reverendryan
71938 in reply to 71919
Anonymous:
Keyboard not found! Press any key to continue...


Actually, that makes perfect sense. The BIOS is giving you an opportunity to plug a keyboard in (when it will still be recognized) before your OS boots and simply assumes that there is never going to be a keyboard.   Especially usefull back in the day when plugging in a keyboard would crash DOS/Windows.

Re: The Never Ending Error

2006-05-09 13:49 • by Shen
Writing errors to a database, though? Seriously, there's nothing wrong with using plain text flat files for things like this.

Or XML *ducks*

Re: The Never Ending Error

2006-05-09 13:54 • by Maurits
71940 in reply to 71939
function executeQuery($string)
{
    return executeQueryHelper($string, 1);
}

function executeQueryIgnoringErrors($string)
{
    return executeQueryHelper($string, 0);
}

function executeQueryHelper($string, $dieOnError)
{
    GetDatabaseConnection();
    $result = mysql_query($sqlText)

    if ($dieOnError and not $result) {
        die(
            "Query failed " .
            writeErrorToLog(
                $_SESSION['USERNAME'],
                "Query Failed: " .$sqlText . " " . mysql_error()
                ,$scriptName
            )
        );
    }

    return  $result;
}

function writeErrorToLog($owner,$description,$script)
{
    $script = str_replace($_SERVER['DOCUMENT_ROOT'], "", $script);
    $sqlText =
        "INSERT INTO errorLog (ownerID,time,description,script) " .
        "VALUES ('" . $owner . ",Now(),'" . $description . "','" . $script . "')";
    executeQueryIgnoringErrors($sqlText, $_SERVER['PHP_SELF']);

    return "";
}

Re: The Never Ending Error

2006-05-09 13:57 • by md2perpe
Recursion is a Good Thing (TM).

Re: The Never Ending Error

2006-05-09 13:57 • by HAWKEYES
Is this what we call nth level recursive error-logging?

Re: The Never Ending Error

2006-05-09 14:19 • by GalacticCowboy
71945 in reply to 71939
XML ducks?

Re: The Never Ending Error

2006-05-09 14:34 • by stjack1
Shouldn't php's maximum execution time kick in a stop the script from running? I don't get why he had to keep rebooting the server, unless he was dumb enough to set php to run sripts forever.

Re: The Never Ending Error

2006-05-09 14:34 • by mpswaim
71947 in reply to 71935

You'd be surprised.  I have errors try to log to the database first before falling back, and occasionally I get an error *in the database log* saying the database is unavailable.  It's good for a laugh every now and then.


  My apps often open a second database connection when logging an error. So, if the first connection goes south, I can get that kind of error. This was fairly common back in the Win16 days when any other TCP/IP traffic had a good chance of FUBARing SQL Server connections if it happened while you were executing SQL. (Microsoft's "fix" was to go to the 32 bit client.)

Re: The Never Ending Error

2006-05-09 14:46 • by nikolas
71951 in reply to 71910
X-Phile:

He must have left the position to move on to management.


yes. you definitely know the business.

Re: The Never Ending Error

2006-05-09 14:55 • by ParkinT

Infinite Recursion n. see loop


 


Loop n. see Infinite Recursion


 


 


Is there another word for "Thesaurus"?

Re: The Never Ending Error

2006-05-09 14:55 • by ParkinT
71955 in reply to 71945

GalacticCowboy:
XML ducks?


They walk in a row (according to a Schema).

Re: The Never Ending Error

2006-05-09 14:58 • by TankerJoe
71956 in reply to 71945
Fat finger problem, the "D" is right next to the "S".

Re: The Never Ending Error

2006-05-09 14:59 • by TankerJoe
71957 in reply to 71945
GalacticCowboy:
XML ducks?


My previous post was in response to this post.... The Real WTF (tm) is this forum software that doesn't allow editing posts.

Re: The Never Ending Error

2006-05-09 15:04 • by Mark H
I like how writeErrorToLog is executed as a side-effect of concatenating its return (a constant "" BTW) with the error message that gets printed out, which is conveniently also a really meaningful constant: "Query failed ".

Re: The Never Ending Error

2006-05-09 15:07 • by KeyJ
I can't help but quote Douglas Adams:

Anything that happens happens, anything that in happening causes something else to happen causes something else to happen, and anything that in happening causes itself to happen again, happens again. Although not necessarily in chronological order.

Re: The Never Ending Error

2006-05-09 15:13 • by stannius
We had a similar problem around here. Basically, if you hit any unhandled exception it would redirect you to an error page. But the error page was only available to logged in users. Attempting to access this page while not logged in would throw an exception which was not being handled. So any time unlogged in users got an error (i.e. on the public part of the site) or if you got an error while logging in, BAM! Stack overflow.

Re: The Never Ending Error

2006-05-09 15:42 • by Tei
71967 in reply to 71963
I see a sql inyection, because the SQL is never quoted with mysql_real_quote or something alike. Or this guys will use some magic php feature that will aturdetect smoke?

Re: The Never Ending Error

2006-05-09 15:51 • by Rico Chet
you all oversee that this code might actually work given that the SQL server that failed was on another machine than the PHP / HTTP server. There might have been an extra database for logging installed on the PHP machine (well, it looks like this wasn't the case), and if it would be not down as well, it'd work.

Re: The Never Ending Error

2006-05-09 16:10 • by Ed
71971 in reply to 71969
Anonymous:
you all oversee that this code might actually work given that the SQL server that failed was on another machine than the PHP / HTTP server. There might have been an extra database for logging installed on the PHP machine (well, it looks like this wasn't the case), and if it would be not down as well, it'd work.


There might be such an extra database.  Unfortunately, since executeQuery doesn't take a second argument, the extra database won't be targetted.  Further, as writeToErrorLog does not check to see if the error was in attempting to write to the error log, it still doesn't matter, because even if it could target the alternate database, a problem with that alternate database could still cause the problem - it just wouldn't happen quite so often.

Re: The Never Ending Error

2006-05-09 16:18 • by Vicki
71973 in reply to 71909
>>The WTF is that the previous maintenance developer didn't investigate

Reminds me a bit of Monday's SharkTank:




...a few weeks ago, the server started reporting errors on the screen.
She then proudly stated that they would simply shut the power off and
turn it back on, and it would work again for a day or two. This
morning, it wouldn't come back - it just ran in an infinite reboot
mode. Only then did they think to call us."

Re: The Never Ending Error

2006-05-09 16:22 • by Jeff S
71974 in reply to 71916
Cooper:
Anonymous:

>>An oversight like this isn't a WTF, sheesh.




The WTF isn't the code. The WTF is that the previous maintenance developer didn't investigate and just rebooted the server any time there was an error that triggered the error trap infinite loop.



That is not a WTF - it is petty incompetence entrained into a support person by our Microsoft-PC environment.

A WTF is when something is done that rises above the level of normal laziness, incompetence,  ignorance, attitude or a combination.

This is not brillant, has no juice and isNotSortOfNull.

In an era of Uncle-Bill-induced reboot-for-memory-leaks, it is the normal learned activity for anybody not supervized by a manager willing to slap the developer/support person/whoever/whatever for not investigating.

Good people - the criteria for acceptance as a WTF is going south in a hurry.


I couldn't agree more.  Clearly, this is all Micro$oft's fault.  Very astute observation.

Re: The Never Ending Error

2006-05-09 16:23 • by Arancaytar
Unfortunately, I once did a similar thing on a website. The error page, like the others, tried to connect to the database server in order to show whether the user was logged in. Of course, if the reason for the error had been a MySQL server failure, trying to connect would just fail again, leading to the error page being included again, and so on.

In my defence, I had been very tired, and removed it the next day before I got the opportunity to see what happened if the database failed...

Re: The Never Ending Error

2006-05-09 16:30 • by Pyromancer
71978 in reply to 71973
Well, there is some hope that sooner or later(more likely much later)script will get a connection to DB thus stoping the infinite loop[:D]

Re: The Never Ending Error

2006-05-09 16:33 • by rsynnott
I nearly did something like this once, too my lasting shame. Then I noticed how very silly it was and fixed it.
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment