A small program (which I haven't been able to strip down to a minimal *failing* version ;) repeatedly opens sockets and does the following (I tested with all permutations of hSetBuffering):
Socket.connectTo ... hPutStrLn h "Data" hPutStr h d debug Io "Reading..:" c <- hGetContents h debug Io "." print c debug Io "*" After several loops, the program fails with: Io: "Reading..:" Io: "." Fail: failed Action: lazyRead Handle: {loc=<socket: 0>,type=semi-closed,binary=True,buffering=none} Reason: Bad file descriptor File: <socket: 0> Which isn't surprising if you take a look at the attached strace. If you read the trace bottom up, you'll find that someone's calling 'close' on fd 4 (and it's not me!) which has already been closed some time ago. Maybe somehow the finalizer for an old handle gets run and the safety precautions in PrelHandle/PrelIO fail for some reason. write(1, "Io: \"*\"\n", 8) = 8 open("/etc/protocols", O_RDONLY) = 0 fcntl(0, F_GETFD) = 0 fcntl(0, F_SETFD, FD_CLOEXEC) = 0 fstat(0, {st_mode=S_IFREG|0644, st_size=1339, ...}) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000 read(0, "#\n# protocols\tThis file describe"..., 4096) = 1339 close(0) = 0 munmap(0x40014000, 4096) = 0 socket(PF_INET, SOCK_STREAM, IPPROTO_TCP) = 0 fcntl(0, F_GETFL) = 0x2 (flags O_RDWR) fcntl(0, F_SETFL, O_RDWR|O_NONBLOCK) = 0 socket(PF_UNIX, SOCK_STREAM, 0) = 4 connect(4, {sin_family=AF_UNIX, path=" /var/run/.nscd_socket"}, 110) = -1 ECONNREFUSED (Connection refused) close(4) = 0 open("/etc/hosts", O_RDONLY) = 4 fcntl(4, F_GETFD) = 0 fcntl(4, F_SETFD, FD_CLOEXEC) = 0 fstat(4, {st_mode=S_IFREG|0644, st_size=699, ...}) = 0 old_mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x40014000 read(4, "#\n# hosts This file desc"..., 4096) = 699 close(4) = 0 munmap(0x40014000, 4096) = 0 *************************************************************************** close(4) = -1 EBADF (Bad file descriptor) close(0) = 0 close(0) = -1 EBADF (Bad file descriptor) *************************************************************************** connect(0, {sin_family=AF_INET, sin_port=htons(8481), sin_addr=inet_addr("127.0.0.1")}}, 16) = -1 EBADF (Bad file descriptor) fcntl(2, F_GETFL) = 0x2 (flags O_RDWR) write(2, "\nFail: ", 7) = 7 write(2, "failed\nAction: connect\nReason: B"..., 51) = 51 write(2, "\n", 1) = 1 _exit(1) = ? -- Volker Stolz * [EMAIL PROTECTED] * PGP + S/MIME _______________________________________________ Glasgow-haskell-bugs mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs