- 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
And commenting is feeding the troll.
Admin
This isn't a WTF at all - it is a workaround to a "feature" of perl running under windows.
The perl "close" doesn't always close the file immediately - at least some versions of perl running under some versions of windows.
I have seen this behavior myself. I spent hours debugging a perl program that closed a file and immediately unlinked it. The unlink would occasionaly fail with a "permission denied" error. Putting a sleep(1) after the close permantly fixed the problem for me.
I know that at least one other person has seen this same behaviour. He posted it the on the win32 perl users mailing list
Admin
So, TRWTF is Perl. If close() does not call sync(), there's something very wrong.
PS: How's your brother?
Admin
What do you imagine it doing?
Admin
I had considered the possibility that antivirus was causing the problem. If I get some free time (hah!) I may try testing the close and unlink on a system without AV installed and see if it fails there.
Admin
So, I do a bit of windows stuff, although not with perl that fits so much better on linux.
I'm curious, when closing a file, what must you do - that Perl might not be doing - to release that file fully back to the O/S?
Admin
Nothing explicit. My code would work most of the time - it only failed sporaticly. I figure:
the internal code of perl does some threading that leads to a race condition on multi-cpu machines. This bug would not show up on unix because you can unlink and open file, and when it is eventually closed, the end result is what you expected.
Antivirus software is holding the file open.
The windows file close function is returning to the caller before the close completes in some cases.
I never investigated any further after finding that the sleep(1) fixed the problem, but I must say that my curiosity is piqued. I may play around a bit more.
Admin
It seems that you are TRWTF.
Goodbye.
Admin
Try to keep up here. As I stated, my code simply opened a file, wrote to it, CLOSED IT, then unlinked it. Sporaticly, the unlink would fail. No other process would have the file open (except perhaps AV).
I suspect that whoever had originally written the code quoted in the article had ran into this and simply gotten into the habit of using a sleep() after every close.
Admin
We have sleeps like that in a lot of our scripts... It comes down to code like this
copy fileA fileB extract some_info from fileB
-- Error FileB does not exist!
WTF?
This happens about 1 in 20 times when FileB is on a windows share... It never happens when dealing with local file systems.
copy fileA fileB sleep 5 extract some_info from fileB
Never has this problem, even if fileB is on a share.
The newb was probably testing against an environment that ran everything off of local disks.
The production execution was probably moving stuff around between different network locations, hence the sleeps were needed.
Newb deserved the Stare(TM), the veteran probably got a support page at 2AM when some job failed.
Not sure why he would have increased 5 to 6 if 5 had worked all of those years.
Admin
Hopefully since this job Dave has grown a little backbone with regard to dirty looks.
Admin
I've seen the exact same thing in C#. Writing temp files that will be closed and then deleted, in a small number of cases (maybe 1 in a thousand) the delete fails for no discernible reason.
Admin
SPORADICALLY FFS.
It ain't Perl, as Perl simply uses the underlying O/S open and close, Perl's close is not threaded, it is not magic, it does not give you AIDS, it does not require a little rest nor a moment of quiet contemplation before or after calling..
I also cannot reproduce the behaviour you somewhat vaguely describe (XP, with AVG).
Admin
Outside of the text processing .. are you really seriously considering Perl as better than C ??
And the glue .. lmao ? sh, php, py, just about anything does it just as fine.
Admin
On the face of it, this looks stupid as there is clearly no relationship between the close mechnism and the following sleep. However depending on the complexity of the application, it's entirely possible that the sleep may be (possibly inadvertantly) preventing race conditions or deadlocks.
You can't just go changing (even stupid) things on a hunch without confirming that QA has available resource to perform suitable regression testing.
Admin
There's no threading problem that is best solved by waiting for a bit.
Any such solution is itself a WTF.
Admin
The fact that nobody made a Meatloaf reference proves there are no women reading this site.
Admin
I'll give you an answer in the morning.
Admin
Let me guess, that was on windows right ?
Admin
Yes. And they are not likely to make things any faster, either.
Admin
Alright . you don't get it do you ?
When you code : write(filename,filecontent) in any language, it asks the OS to do that alright ?
Then the OS uses the drivers to have the HDD do it
Then it receives the ACK for the last write instruction
THEN it returns.
There is no valid reason to wait 1ms after that, unless the above is not true, i.e. your OS is broken.
Admin
Admin
Nah it's just that people got used to coding fail-OS workarounds right into applications - to the point where they don't even realize how ridiculous the root cause is.
Admin
Admin
Again, if the O/S doesn't flush on close then waiting a millisecond or two isn't going to do it either.
Admin
The filesystem is the whole caboodle, O/S, memory, cache, raid controller, device drivers, flash ram, disk surface. It's not just the disk platter surface.
When you write, you write to the filesystem, the filesystem decides whether it goes on the disk or not. Similarly when you read it needn't have gone anywhere near the disk at all, but the filesystem will be consistent, because that's what filesystems do.
...if they aren't broken.
Admin
Of course there's disk write caching.
IF IT DOESN'T happen that way, your OS is broken.
B R O K E N
If you don't get that, you should stop working in IT, you're only going to create more broken stuff.
hint: even with disk caching, your os can and should behave like said above AND the only way it would fail is if you had asked for an async system call and in that case, you are TRWTF for going async + wait instead of sync.
Admin
Admin
Got both of us there. >:(
Admin
TRWTF is CVS. Seriously? In 2012?
Admin
I escaped my parentheses once, but the police brought me back and my parentheses were very angry. :-(
Admin
the real WTF is that Paradise By The Dashboard Light was by Meat Loaf, not Alvin Stardust..
Admin
and now it appears even Engelbert Humperdinck wants his piece of the action.
Admin
взять моментальный кредит webmoney