[If you are interested in reproducing the exact setup, please contact me]
I did some hello-debugging in PrelHandle
and found out the following:

....

'lazyRead' gets the last input and invokes hClose_help which closes the
filehandle as it should:

read(0, "", 8192)                       = 0
write(1, "hClose_help!\n", 13)          = 13
close(0)                                = 0

The following is some junk generated by the program, including the next
connection attempt

write(1, "\"KeyCollision\\nURI=freenet:KSK@f"..., 132) = 132
write(1, "Io: \"*\"\n", 8)              = 8
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
...
connect(0, {sin_family=AF_INET, sin_port=htons(8481), 
sin_addr=inet_addr("127.0.0.1")}}, 16) = -1 EINPROGRESS (Operation now in progress)
gettimeofday({1005733385, 497583}, NULL) = 0
select(1, [], [0], NULL, {134, 217727}) = 1 (out [0], left {134, 220000})
getsockopt(0, SOL_SOCKET, SO_ERROR, [0], [1]) = 0
fcntl(0, F_GETFL)                       = 0x802 (flags O_RDWR|O_NONBLOCK)
fcntl(0, F_SETFL, O_RDWR|O_NONBLOCK)    = 0
fstat(0, {st_mode=S_IFSOCK|0777, st_size=0, ...}) = 0
ioctl(0, TCGETS, 0xbfffcf78)            = -1 EINVAL (Invalid argument)
ioctl(0, TCGETS, 0xbfffcf78)            = -1 EINVAL (Invalid argument)

Things get interesting here: A finalizer for one of the previous
connections gets run. But the strace did show that *all* (not only the
last one I included above) got already closed by hClose_help!

It looks like the filehandle is protected by an MVar which should take care
of setting the fd to -1 when the hClose_help runs, but:

write(1, "Finalizer!\n", 11)            = 11
close(4)                                = -1 EBADF (Bad file descriptor)
write(1, "Done!\n", 6)                  = 6
write(1, "Finalizer!\n", 11)            = 11
close(0)                                = 0
write(1, "Done!\n", 6)                  = 6
write(1, "Finalizer!\n", 11)            = 11
close(0)                                = -1 EBADF (Bad file descriptor)
write(1, "Done!\n", 6)                  = 6
write(1, "Finalizer!\n", 11)            = 11
close(0)                                = -1 EBADF (Bad file descriptor)
write(1, "Done!\n", 6)                  = 6
write(1, "Finalizer!\n", 11)            = 11
close(0)                                = -1 EBADF (Bad file descriptor)
write(1, "Done!\n", 6)                  = 6

Ooooops. The finalizers blew it. The "Done!" is exactly after the c_close
in PrelHandle.hsc, so while the "Finalizer!" output should appear in any
case, the "Done!" indicates that the fd wasn't set to -1 as one might
have thought?!

Trailing garbage from the program mnot stripped for completeness.

write(1, "Io: \"Reading..:\"\n", 17)    = 17
write(0, "\0\0\0\2ClientPut\nHopsToLive=0\nURI=K"..., 158) = -1 EBADF (Bad file 
descriptor)
fcntl(2, F_GETFL)                       = 0x2 (flags O_RDWR)
write(2, "\nFail: ", 7)                 = 7
write(2, "failed\nAction: hFlush\nHandle: {l"..., 157) = 157
write(2, "\n", 1)                       = 1
munmap(0x40014000, 4096)                = 0
_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

Reply via email to