• Little Bobby Tables (unregistered)

    That's odd.

  • ray10k (unregistered) in reply to Little Bobby Tables

    Have my (+1)+1 and get out.

  • (nodebb)

    You're wondering why he would want to sleep for 2 seconds, but you answered your own question, that block will never execute, therefore he doesn't want to sleep for 2 seconds.

  • King (unregistered)

    I think the original idea was to not upset the smtp-server by sending "too many" mails in a short period. I guess the mail provider solved it by removing that rule. Code works. Nothing to see. Carry on.

  • (nodebb)

    I want to see what the parent loop does. Is there a sleep there?

  • (nodebb)

    It could be that the elseif is copypasta by a moron that didn't understand what the if was doing.

    The mail server rejecting too many messages in a span of time is unfortunately real for some mail server setups. The way around it, if you run into it, is to learn how to use the CC field (seriously).

  • Brian (unregistered)

    I wonder if this started life with $counter++, and then some overly-zealous optimizer came along and "fixed" it, all the while laughing at the stupid noob who used the postfix-increment, because any Real Programmer worth his salt knows that prefix-increment is faster.

  • (nodebb)

    At work, shortly after installing new firewall hardware, we lost connection to our external mail server for a morning because the new firewall was blocking outbound email handshakes on the way in. This meant that all the emails that people generated just stayed in their Outlook outboxes, unless they were using the webmail. When we finally got the firewall working nicely, everybody's blocked emails flooded our service provider. For most users, they dumped about a dozen emails they wrote that morning and went through fine, but our buyer had been generating purchase orders for most of the morning to about 400 vendors. The email server only allowed 100 in the first rush and then blocked her for a while before lettering the next batch of 100 through; by the end of the day, all the purchase orders went out to their respective recipients. That looks like just this type of anti-spam measure that was mentioned in the article.

  • Gumpy_Gus (unregistered)

    Long ago I was trying to send email from a csh script, on a small Sun workstation. After a few dozen issues with the broken csh syntax and semantics, then there were timing issues. Many sleeps scattered around the code ensure things didn't get ahead of themselves. The code never worked reliably. Then one day I tried a direct SMTP connection from C and it WORKED FIRST TIME. I never looked back.

  • D-Coder (unregistered) in reply to Zenith

    "The way around it, if you run into it, is to learn how to use the CC field (seriously)."

    And if the emails have customer information... well, you'd have a different WTF.

  • Just here (unregistered)

    Have more than 51 items in queue? Don't care! After processing and sending 51 items, this will break; That should avoid sending "too many" emails in a short period.

  • anonymous (unregistered)

    Depending on the initialisation value of the counter, this conditional block might sleep... once.

    If the counter is initialised with an odd value less than 100, it will count up in 2s until it gets to something that's divisible by 10, minus 1. Then it will increment the counter once, and it will be divisible by 10. On that iteration, the second conditional is skipped so on the next iteration it starts off even instead of odd, and counts up in 2s. Thus the conditional is never true again.

    Similarly, changing the conditional to a post-increment instead of a pre-increment and starting off with an even counter value would work until the first time the conditional is true, then the counter will end up odd.

    TRWTF is why they want to sleep only on every 10th iteration and only run for 100 iterations even if there's more data to process. Or perhaps if this is appropriate behavior they should use a for loop limited to 100 iterations and then break out of the loop if there's no more data.

  • Doodpants (unregistered)

    Are you sure it's supposed to sleep for 2 seconds? Most sleep() functions that I'm familiar with take a parameter of milliseconds, not seconds.

  • anonymous (unregistered)

    Never mind, I missed the line where the counter is initialised. Still interesting though.

  • ZZartin (unregistered)

    Oh and also hope you never get a back log of more than 50 items.

  • Klimax (unregistered)

    OK. Explanation is incomplete. Why would second if take precedence over first one causing it to be skipped?

  • Brian (unregistered) in reply to Klimax
    Klimax:
    OK. Explanation is incomplete. Why would second if take precedence over first one causing it to be skipped?

    Because (assuming this works like C) the prefix-++ increments the variable before evaluating the rest of the statement. So it starts at 0, increments to 1, checks against mod-10, then increments to 2. Next iteration: increment to 3, check against mod-10, increment to 4. And so on. It's always an odd number for that first check, so counter % 10 is never 0.

  • I dunno LOL ¯\(°_o)/¯ (unregistered)

    500 - Internal Server Error

    An error occurred while processing the request. If this error continues, please reach out to an Administrator using the contact form.

    If this error was generated by the contact form, please send an email to Alex directly at alexp/worsethanfailure/com

    This is the perfect TDWTF article. Cheers, Remy!

  • RLB (unregistered) in reply to Brian

    C++ premature optimisation in half-baked PHP code. I wouldn't be surprised.

  • hmm (unregistered)

    The counter starts from 0 it can reach value of 10. But after that it always odd number. So it sleeps once.

  • (nodebb) in reply to D-Coder

    Well, yeah, if you start there rather than newsletters and advertisements, you've got two WTFs on your hands.

  • medievalist (unregistered) in reply to Zenith

    "The mail server rejecting too many messages in a span of time is unfortunately real for some mail server setups. The way around it, if you run into it, is to learn how to use the CC field (seriously)."

    Generally email admins limit number of messages in a single transmission, number of messages per user over a set period of time, and number of addressees per message. All of these include the CC and BCC recipients in their counts.

    This not only cuts out a lot of spam and marketing nobody wants, it means that real person-to-person emails aren't (as often) completely swamped by program-generated email.

    Source: been an email admin (among other things) since before the Internet, and still am.

Leave a comment on “Count Me Out”

Log In or post as a guest

Replying to comment #:

« Return to Article