1. Nov 7th, 2005

    Forking Ruby makes MySQL go away

    The following lines:

    fork {  # do nothing}

    Leads to the following error:

    reliable-msg: MySQL server has gone away./lib/reliable-msg/message-store.rb:155:in `query':   MySQL server has gone away (Mysql::Error)

    I’m running Ruby 1.8.3 on Cygwin 1.5.18 and MySQL 4.1. The MySQL server is running as an NT service. Anyone seen this before? Any ideas?

    1. Nov 10th, 2005

      Michael Granger

      That happens when something clobbers the socket in your handle to the db. Since fork() isn’t implemented in win32, there must be something funky in Ruby’s fork() emulation that’s invalidating the socket in your handle.

      Do you really need to fork? You can use Thread {} for simultaneity, and if you just want a daemonized process, Daniel Berger has an excellent module that lets you write Win32 services in Ruby: http://raa.ruby-lang.org/project/win32-service/

    2. Nov 17th, 2005

      Assaf

      thanks.

      one case where I would like to fork the code is calling Open3, so I can run a shell command that may not exist, and detect it from stderr.

      doing %x{} or anything else displays an error in the console.

      I’d also want to play with processes to see if there’s any performance difference from threads.

    Your comment, here ⇓