lostcarpark: (Lego T-Rex eating Jar-Jar)
[personal profile] lostcarpark
When you have a loop in your code, make sure it has an exit condition that will always occur.

I though I was the victim of a DoS attack on one of my websites, but it turned out to be entirely self inflicted.

Date: 2007-05-18 11:01 pm (UTC)
spodlife: Tardis and Tim (Dalek)
From: [personal profile] spodlife
Apparently the code in nuclear missiles doesn't have an exit point - it loops until impact!

Date: 2007-05-19 12:36 am (UTC)
From: [identity profile] lostcarpark.livejournal.com
Okay, there are exceptions... a less destructive example was when I used to write Spectrum games, it was considered perfectly to have an infinite loop control the game. When the user gets bored, they pull the plug (the Spectrum didn't even have an off switch).

When the code is generating part of a web page, however, infinite loops are very bad indeed. Every time the page is loaded it will create a new thread of execution, tying up server resources and never giving them back, until the server has no more resources to give. As every iteration of the loop was writing a line to my error log, this also grew at an alarming rate, writing 10GB to the log in a matter of minutes.

It was also consuming 100% of CPU resources, so if I hadn't dealt with it quickly I expect my webhost would have been none to happy.

January 2016

S M T W T F S
     12
3456789
10111213141516
17181920212223
24252627 282930
31      

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Jan. 10th, 2026 12:51 pm
Powered by Dreamwidth Studios