- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
The WTF is obviously an infinite recursion but the OP doesn't read like "filled up the file system and crashed". The application froze.
Probably because it takes a long time to fill the whole swap space with an infinitely growing stack, especially in an interpreted language like PHP.
I'm sure every programmer knows the difference between loops an recursions (at least all programmers who know recursion at all), it's just sloopy wording to say "infinite loop" to an infinite recursion.
Admin
Oh btw for those that are saying that this would cause a loop for a database being down, your wrong.
Again we can only persume that it would get that far since we don't have the code for GetConnection function...
Agian this really doesn't appear to be a WTF at all...
Admin
Calling die is just plain lazy anyway.
Admin
My joke about file systems did not turn out well, but my point is that recursion and loops are fundamentally different. There is virtually no case for allowing infinite recursion, but plenty of cases for infinite loops, e.g., daemons. Even if the runtime system intervenes in stack problems, or a profiler converts recursion to loops, it is still bad practice to use recursion without constraint.
I'm not saying recursion should never be used. It is the natural way to traverse linked lists, for example, but if you did that there would have to have constraints to ensure that the list was not circular. Oracle's CONNECT BY clause is a good example of how to do it.
The recursion in the code looks like an oversight, so it is hard to say whether a firmer grounding in fundamentals would have prevented it; what bothers me is the discussion here not making the distinction. Do they really not know what the computer is doing with their code?!
Admin
die() generates an exception and exits the program with the argument as an error message in STDOUT if not caught -- in Perl at least.
-dZ.
Admin
Sorry, that should have been "...error message in STDERR...". This keyboard can't spell correctly, jeez!
-dZ.
Admin
I learned about recursion when I was a little girl, before I ever used a computer. I learned it from "Doctor Who" (the episodes "Logopolis" and "Castrovalva"). Recursion doesn't often show up in pop TV, but this was an exception. In the latter story, Tegan was trying to find some kind of index to the TARDIS computer to help them pilot the ship while the Doctor was incapacitated.
Tegan: Of course, if you had an index file, you could look it up in the index file under "index file"! What am I saying? That's nonsense.
Nyssa: Recursion's not nonsense.
Tegan: Eh?
Nyssa: Recursion's when procedures fall back on themselves. If you had an index file, you could look it up in the index file.
Admin
Anyway, its a nice example of mutual recursion gone bad.
Admin
From page 1:
No, it is you whom have missed my point.
mysql_query fails on more than just the server going bye bye. Give it a bad query and it will fail, which would then cause the error to be inserted, which if tested at least once, should be syntactically correct.
Like I said, if you slap an "if not connected" before making the query and use error_log() instead (which they don't appear to use set_error_handler()) then there's no infinite recursion. Better yet, check if executeQuery is in the stack and bail or error_log if it is (on the off chance your error INSERT is incorrect).
(For the non-PHP out there, error_log() routes to apache's error log (or the like). IOW: not DB based!)
THE CODE IS NOT A WTF. An oversight at worst. Writing any kind of logging system requires asking the question of "what happens when I error in my error handlers?" Clearly, the given code's coder didn't ask themself this. Still not a WTF.
The maintainer just rebooting the machine is more in the realm of stupidity/lazyness than a WTF.
Admin
Not really. It may look like that if you only know languages like C, C++, Java, C# etc. But there are other languages where there is no explicit loop construct, just recursion.
There might be no case for unconditional infinite recursion, but in CS there are lots of problems (e.g. determining the validity of formulas in first order logic) which can be solved, if at all, by recursion; unfortunately it's not possible to determine the necessary recursion depth, if a solution exists at all.
A loop is good enough for linked lists. Traversing trees is a much better example.
Admin
Get a room you too.
The point is that unbounded or infinite recursion eats the stack for lunch, loops don't.
Admin
IT professionals? WTF??? Where did you see those?
Admin
That would sum up multiple threading exeution nicely.
Admin
Admin
Oh my God, "fantasy baseball"! Baseball must be the most uninteresting game in the world! More like "nightmare baseball"!
Admin
GASP! People have different interests and enjoy different entertainment products! Stop the presses!
Go away.
sincerely,
Richard Nixon
Admin
I admit I've done this one, tho I did also figure out I was doing it, and then fixed it :-)
Admin
You contradict yourself. First, it's NOT a WTF because it is incompetence, then a true WTF IS laziness and incompetence....both of which are shown here. The original maintainer was described as a programmer, i think. Laziness in not looking into the code, incompetence in not realizing he could.
I vote WTF.
Admin
right, the random conditions injection principal. That the same code run over and over against the same environment and situation, will eventually do something completely different :-)
Admin
Why should you need to duck? My apps store error message logs as XML.
Admin
The real WTF is how a bunch of IT professionals can never agree on what the real WTF is, EVER!
Yes, of course. Because a bunch of smart people can't have different or even dissenting views - that would mean the world is a complicated place, full of people with different opinions. Ridiculous!
Admin
No one said there was anything wrong with writing errors to a flat file. Why do you think errors shouldn't be written to a DB?
sincerely,
Richard Nixon
Admin
Well, I'm not sure it's exactly accurate to say that die() "generates an exception." The Perl docs say, "This makes
die
the way to raise an exception." Therefore, if die() were to throw an exception, it would need to call die(), which then would attempt to throw an exception, for which it would need to call die(), ...But this is beside the point. Before die() can put the script out of its misery, the interpreter will need to evaluate the arguments to pass to die(), which involves logging the error to the database first.
Admin
Sorry, I probably didn't make it too clear what I as referring to...
Reply to an Existing Message
die() generates an exception and exits the program with the argument as an error message in STDOUT if not caught -- in Perl at least.
-dZ.
Well, I'm not sure it's exactly accurate to say that die() "generates an exception." The Perl docs say, "This makes die the way to raise an exception." Therefore, if die() were to throw an exception, it would need to call die(), which then would attempt to throw an exception, for which it would need to call die(), ...
But this is beside the point. Before die() can put the script out of its misery, the interpreter will need to evaluate the arguments to pass to die(), which involves logging the error to the database...
Admin
The real WTF is that PHP doesn't optimize tail-recursion. I propose we rewrite the PHP interpreter so it optimizes this into an infinite loop (and get rid of the pesky 'return ""' so the program becomes tail-recursive). Then all the loop-vs-recursion arguments become strictly academic.
Admin
<FONT color=#800080>Are these licensed?<br> <a href="" target="_blank"><img src="http://www.thinkgeek.com/images/products/front/lg-girl-wtf.jpg" border = "0" alt="WTF?"></a></FONT>
Admin
In this case the max-execution and max-memory were set ridiculously high as the the page had to be able to upload LARGE files over http. (Who'd want something as primitive as ftp ;) )
The problem occurred when some customers started uploading dodgy files and caused the error log to be tripped. It doesn't take long to bring down a server with multiple processes eating ram like it's going out of fashion.