5

My program runs with runghc but the same program consistently fails when compiled with error "Lost connection to MySQL server during query". The fail is not associated with a long running query (it is a CREATE VIEW on a small table). There is nothing in the MySQL error-log, and log_warnings=1. Environment - ubuntu (13.04 ;-), local database)

hdb3
  • 239
  • 1
  • 10
  • Try setting log_warnings=2 (http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_log-warnings). What OS, what version of ghc? Can you reduce your code to a simple example that still exhibits the problem and post that code? – ja. Apr 13 '13 at 14:54
  • Thanks for suggestion. I have a very simple example that fails: http://pastebin.com/9vrStfs7 I switched from HDBC.ODBC to HDBC.MySQL, but the problem stays. I switched to use network access 9on loopback i/f), same problem but now I can see the traffic! I set log_warnings=2, No new messages in the log file, however I found in /var/log/mysql/error.log the following: "[Warning] Aborted connection 243 to db: (Got an error reading communication packets)" Also, the tshark pkt trace shows the client disconnects before the server responds (about 200mS). With runghc the server response is at 300 mS – hdb3 Apr 13 '13 at 17:00
  • Do you know how you set the MySQL client server response timeout? – hdb3 Apr 13 '13 at 17:03
  • 3
    Does calling [withRTSSignalsBlocked](http://hackage.haskell.org/packages/archive/HDBC-mysql/0.6.6.1/doc/html/Database-HDBC-MySQL.html#v:withRTSSignalsBlocked) make a difference? I guess runghc uses non-threaded runtime and your compiled program uses threaded runtime. – snak Apr 14 '13 at 14:07
  • 2
    @snak - bingo! - withRTSSignalsBlocked fixes it - though nowhere do I explicitly call for threaded RT. In fact, the ghc command line I used (ghc Test.hs) has to be changed to 'ghc -threaded Test.hs' to get the code using withRTSSignalsBlocked to compile! I'd say the documentation leavses something to be desired. Hopefully the next novice will find this thread..... – hdb3 Apr 16 '13 at 20:29

1 Answers1

3

HDBC.ODBC must use 'withRTSSignalsBlocked' to protect all database access actions, or risk random failures such as I describe. This was effectively confirmed by the author of the library.

hdb3
  • 239
  • 1
  • 10
  • I wrapped a [**`Database.HDBC.ODBC`**](http://hackage.haskell.org/package/HDBC-odbc-2.2.3.0/docs/Database-HDBC-ODBC.html) connection & query in [**`withRTSSignalsBlocked`**](http://hackage.haskell.org/package/HDBC-mysql-0.6.5.1/docs/Database-HDBC-MySQL.html#v:withRTSSignalsBlocked) from the [**`Database.HDBC.MySql`**](http://hackage.haskell.org/package/HDBC-mysql-0.6.5.1/docs/Database-HDBC-MySQL.html) and the erratic runtime behaviour ***vanished!*** – recursion.ninja Aug 27 '14 at 14:56