GHC 7 can't do IO when demonized
If a daemon is complied with GHC 7.1 with the -threaded option, the daemon cannot do IO. The following code is a simple echo server which demonstrates this bug:
import Control.Concurrent
import Network
import System.IO
import System.Posix.Daemonize
main :: IO ()
main = daemonize $ do
s <- listenOn (Service "7000")
loop s
return ()
loop :: Socket -> IO ThreadId
loop s = do
(hdr,_,_) <- accept s
forkIO $ echo hdr
loop s
echo :: Handle -> IO ()
echo hdr = do
str <- hGetLine hdr
hPutStrLn hdr str
hClose hdr
return ()
If "deamonize $" is removed, this program stays in your terminal and can do IO.
Trac metadata
Trac field | Value |
---|---|
Version | 7.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |