[Haskell-cafe] readFile problem

Stefan Aeschbacher haskell at aeschbacher.ch
Mon Jan 8 06:56:45 EST 2007


2007/1/8, Neil Mitchell <ndmitchell at gmail.com>:
> Hi Stefan,
> > I am writing a network server in haskell. Lately I seem to have
> > introduced a new bug. On Linux, when a client closes the connection to
> > the server, the server dumps core.
> Are you using any calls to system? Any libraries which may do funky stuff?
No calls to system. Libraries I use: MissingH (only some time
function) and HaXML.

> > application.exe: config.xml: openFile: does not exist (No such file or
> > directory)
> >
> > I use readFile to read the config file. I tried to print out the
> > config file after it is read to make sure that it is completely read.
> > I only load this config file exactly once during program
> > initialization. The config is used long before the crash. I printed
> > the current working dir in the exception handler and there is
> > something interesting. Instead of the path to the application, it is
> > "\C:\\WINDOWS\\system32".
> What is the working directory at the begining? Is that really the
> working directory? The "\C" at the start isn't the C drive, but some
> bizare escape code, I think.
Oups, I think i must have slipped that first \ in by mistake during
the composition of the mail. The path at the start of the application
is d:\development\simulator_v2 and when the error occurs it is
C:\WINDOWS\system32 (without the show i used before).

In the last hours I found out the following:

the program looks something like this:

main = do withSocketsDo $ runSimulator

runSimulator = do
  dir <- getCurrentDirectory
  putStrLn ("Dir is: " ++ dir)
  config <- readConfig
  fork many threads

It seems as if runSimulator is executed twice when the error happens.
The first time dir is printed correctly (d:...). Then the application
starts, all threads are created and it runs normally. When the client
closes the socket the error: "<socket: 1832>: hGetChar: failed
(Unknown error)" happens (which in my eyes should rather be
isEOFError?). Then the withSocketsDo seems to execute runSimulator
again (dir then is C:...).



More information about the Haskell-Cafe mailing list