Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] GC and file descriptors
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: tim@f...
Subject: [Caml-list] Bugs from ignoring errors from close (was Re: GC and file..)
On Fri, 2003-11-14 at 21:25, Max Kirillov wrote:
> According to 'man 2 close', it cannot.

From: Mike Furr <mike.furr@umbc.edu>
>Sure it can: EINTR.  And to prove this can actually can happen,
>just ask the squid(web proxy) developers.  I seem to recall hearing a
>talk by one of them where they mentioned the failure to check the return
>code of close() resulted in a out-of-fd bug which took a _long_ time to
>track down.

In another context I've solved a bug that was hard to find in part
because someone ignored the return status from close.  Here's the
scenario:

Thread 1				Thread 2

1. int fd1 = open (...)

2. close(fd1)

					3. int fd2 = open (...)

4. bad code called close (fd1) again, ignoring errors.

					5. read (fd2, ...) and
                                           occasionally fail!

When the steps happen to happen in this order, fd2 can equal fd1, so
the second close closes fd2 also and the read occasionally failed.

Don't ignore errors on any system calls.

-- 
Tim Freeman                                                  tim@fungible.com
GPG public key fingerprint ECDF 46F8 3B80 BB9E 575D  7180 76DF FE00 34B1 5C78 
Your levity is good. It relieves tension and the fear of death. -- Terminator 3

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners