socketToHandle, hGetContents cause errors in ghci
I wrote a server using socketToHandle and hGetContents.
The first request worked fine, but the second request
crashed with "internal error: scavenge_stack: weird
activation record found on stack: 9". I tried to
create a test case. I couldn't reproduce the same
problem, but I did get an intermittent "Bad file
descriptor". I think it may be a related problem, and
it may have to do with garbage collection (based on a
strace showing a call to getrusage).
The program is below, and when I run it with runghc and
feed it a line of input with nc, it crashes on the 17th
request. It's not important to me that you fix it; in
fact I only tried this as an experiment to simplify
some working code. But if you would like more
information, let me know.
I am using the Debian package ghc6 6.4-4.
import Network.Socket
import System.IO
main = do
s <- socket AF_INET Stream 0
h <- inet_addr "127.0.0.1"
bindSocket s (SockAddrInet 1236 h)
listen s 5
loop s
loop listenSock = do
(s,_) <- accept listenSock
h <- socketToHandle s ReadMode
input <- hGetContents h
putStrLn (take 10 input)
send s "got it\n"
sClose s
loop listenSock
Trac metadata
| Trac field | Value |
|---|---|
| Version | None |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | ResolvedNoReason |
| Component | libraries/network |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |