• (cs) in reply to RyuO
    RyuO:
    ParkinT:

    Infinite Recursion n. see loop

     
    Loop n. see Infinite Recursion


    Is there another word for "Thesaurus"?


    The scariest WTF here is that people are equating infinite recursion with infinite loops. Recursion tends to be bad for memory, while an infinite loop can run on for years minding its own business.

    If this WTF had been coded by someone who knew the difference between loops and recursion, it would have filled up the file system, which at least would have resulted in a clear exception.


    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.

  • Salizar (unregistered) in reply to Salizar

    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...

  • someone (unregistered)

    Calling die is just plain lazy anyway.

     

  • (cs) in reply to ammoQ
    ammoQ:
    RyuO:
    ParkinT:

    Infinite Recursion n. see loop

     
    Loop n. see Infinite Recursion


    Is there another word for "Thesaurus"?


    The scariest WTF here is that people are equating infinite recursion with infinite loops. Recursion tends to be bad for memory, while an infinite loop can run on for years minding its own business.

    If this WTF had been coded by someone who knew the difference between loops and recursion, it would have filled up the file system, which at least would have resulted in a clear exception.


    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.


    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?!

  • (cs) in reply to bob
    Anonymous:

    anyone want to explain what the Die function does? Is that the basis of the WTF? Because otherwise, I don't see why it'd hang since the DB could be down for a second and then come back up, the bad query gets logged at that point and everything continues...

    But logging to the DB is prob not a great idea for this reason,



    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.
  • (cs) in reply to DZ-Jay
    DZ-Jay:
    Anonymous:

    anyone want to explain what the Die function does? Is that the basis of the WTF? Because otherwise, I don't see why it'd hang since the DB could be down for a second and then come back up, the bad query gets logged at that point and everything continues...

    But logging to the DB is prob not a great idea for this reason,



    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.


    Sorry, that should have been "...error message in STDERR...".  This keyboard can't spell correctly, jeez!

         -dZ.
  • CalliArcale (unregistered) in reply to RyuO
    RyuO:
    ParkinT:

    Infinite Recursion n. see loop

     
    Loop n. see Infinite Recursion


    Is there another word for "Thesaurus"?


    The scariest WTF here is that people are equating infinite recursion with infinite loops. Recursion tends to be bad for memory, while an infinite loop can run on for years minding its own business.

    If this WTF had been coded by someone who knew the difference between loops and recursion, it would have filled up the file system, which at least would have resulted in a clear exception.


    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.
  • (cs) in reply to DZ-Jay
    DZ-Jay:
    Anonymous:

    anyone want to explain what the Die function does? Is that the basis of the WTF? Because otherwise, I don't see why it'd hang since the DB could be down for a second and then come back up, the bad query gets logged at that point and everything continues...

    But logging to the DB is prob not a great idea for this reason,



    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.
    But, at the time die was introduced in PHP (wich was back in the PHP3 days), PHP didn't yet support exceptions of any kind at that time. Die(), under PHP outputs the text passed to it and stops the script.
    Tei:
    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?
    There can't even be SQL-injection as the query never gets executed, mysql_query gets a $sqlText which is not defined in the executeQuery function and is, thurs, empty. (The parameter is called $string).
    GoatCheez:
    Simply put: This is why global variable scope is evil.
    Which global variable are you refering to? There aren't any in the code above, except for the predefined superglobals.

    Anyway, its a nice example of mutual recursion gone bad.

  • Colin (unregistered) in reply to loneprogrammer

    From page 1:

    loneprogrammer:
    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.

    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?


    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.
  • (cs) in reply to RyuO
    RyuO:

    ... my point is that recursion and loops are fundamentally different.

    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 is virtually no case for allowing infinite recursion, but plenty of cases for infinite loops, e.g., daemons.

    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.

    I'm not saying recursion should never be used. It is the natural way to traverse linked lists,

    A loop is good enough for linked lists. Traversing trees is a much better example.
  • Roy (unregistered) in reply to ammoQ

    Get a room you too.

    The point is that unbounded or infinite recursion eats the stack for lunch, loops don't.

  • (cs) in reply to Junior IT Professional
    Anonymous:
    The real WTF is how a bunch of IT professionals can never agree on what the real WTF is, EVER!

    IT professionals? WTF??? Where did you see those?
  • (cs) in reply to KeyJ

    Anonymous:
    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.

    That would sum up multiple threading exeution nicely.

  • plrf (unregistered) in reply to powerlord
    powerlord:
    Tei:
    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?


    PHP calls it "magic_quotes."  I would link to it in the online manual but the forum software isn't letting me create links.  Here's the URL: http://www.php.net/magic_quotes
    actually it's http://www.php.net/mysql_real_escape_string
  • Robin McKenzie (unregistered) in reply to Bus Raker

    Oh my God, "fantasy baseball"!   Baseball must be the most uninteresting game in the world!  More like "nightmare baseball"!

  • (cs) in reply to Robin McKenzie
    Anonymous:
    Oh my God, "fantasy baseball"!   Baseball must be the most uninteresting game in the world!  More like "nightmare baseball"!


    GASP! People have different interests and enjoy different entertainment products! Stop the presses!

    Go away.

    sincerely,
    Richard Nixon
  • (cs)

    I admit I've done this one, tho I did also figure out I was doing it, and then fixed it :-)

  • (cs) in reply to Cooper
    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.


    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.
  • (cs) in reply to Pyromancer
    Anonymous:
    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]


    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 :-)

  • Gary Wheeler (unregistered) in reply to Shen

    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*

    Why should you need to duck? My apps store error message logs as XML.

  • (cs) in reply to Junior IT Professional

    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!

  • (cs) in reply to Shen
    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



    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

  • Holger Friedrich (unregistered) in reply to DZ-Jay

    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.

  • Holger Friedrich (unregistered) in reply to DZ-Jay

    Sorry, I probably didn't make it too clear what I as referring to...

    Reply to an Existing Message

    [image] Anonymous wrote:

    anyone want to explain what the Die function does? Is that the basis of the WTF? Because otherwise, I don't see why it'd hang since the DB could be down for a second and then come back up, the bad query gets logged at that point and everything continues...

    But logging to the DB is prob not a great idea for this reason,


    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...

  • Schemer (unregistered) in reply to Joshua

    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.

  • (cs)

    <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>

  • Niall (unregistered) in reply to stjack1
    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.

    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.

  • GeraldDew (unregistered)
    Comment held for moderation.

Leave a comment on “The Never Ending Error ”

Log In or post as a guest

Replying to comment #:

« Return to Article