Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2003-11-16 (05:22)
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 <>
>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

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                                        
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 Archives:
Bug reports: FAQ:
Beginner's list: