Question

The Snap and Groundhog work separately but when combined (see below), snap crashes with a core-dump (segment fault or an access violation). These already worked together but problems started after ubuntu upgrade. (Or I have made some change I cannot see now.)

The snap works without wC <- getiCount -line. How to fix this one?

Addition based on comment: now there are logError messages around (SC refers to Snap.Core). When it crashes, it does not log any messages to log/error.log nor does it produce output to www-page. If runGH-line is commented and then next line used, all error messages and output to www-page is produced as expected.

2nd addition, inserted a separate file appends with wFile-function to show, where the program crashes: this shows that runGH2 is last addition to the file. Somehow the logErrorgives nothing (I tried runStdoutLogging) before crash. It seems that the program does not get to the iCount-function.

In Application.hs

runGH :: ConnectionManager b conn => DbPersist conn (NoLoggingT IO) a -> Handler b v a
runGH f = do 
  liftIO $ wFile "runGH"
  withTop' id $ do
    cm <- ask
    SC.logError "runGH2" 
    liftIO $ wFile "runGH2"
    liftIO $ runNoLoggingT (withConn (runDbPersist f) cm)

wFile txt = withFile "fmsg.txt" AppendMode $ \h -> hPutStrLn h ("log msg: " ++ txt)

and in Site.hs

initDBP :: (MonadIO m, MonadBaseControl IO m) => m (Pool Sqlite)
initDBP = withSqlitePool "mydb.sqlite" 5 $ \pconn -> return pconn

handleCntPage :: Handler App ({- AuthManager -} App) ()
handleCntPage = do 
    SC.logError "handleCntPage, 1st line"
    writeText $ T.pack ("Soon we count number of db-items. " )
    wC <- getiCount
    SC.logError "handleCntPage, almost last line"
    writeText $ T.pack ("we count number of db-items." ++ (show wC))

getiCount :: (ConnectionManager b conn, PersistBackend (DbPersist conn (NoLoggingT IO))) => Handler b v Int
getiCount = do
  liftIO $ wFile "getiCount"
  SC.logError "getiCount, 1st line"
  i <- runGH $ iCount -- this does not work
  liftIO $ wFile "getiCount2"
  -- let i = 10 -- this works
  SC.logError "getiCount, after call"
  return i

and iCount has been tested separately and it works without snap:

iCount :: (PersistBackend m) => m Int
iCount = do
   liftIO $ wFile "iCount"
   i <- countAll (undefined :: Items)
   liftIO $ wFile "iCount2"
   -- let i = 10 -- commenting the above line and using this one still crashes
   return i
Was it helpful?

Solution

I think that all libraries you use are compatible. However, some packages got broken. Maybe Ubuntu upgrade replaced Haskell packages you installed via software center instead of cabal. Cabal sandbox would help for this particular project, but removing all packages and rebuilding them will prevent similar problems for other projects too.

My cabal packages are FUBAR; how can I purge them and start over?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top