async_exec stops in win32 environment

Issue #16 resolved
shun created an issue

async_exec stops when there is any other thread than current thread in win32 environment. Ofcourse, it works well with Linux.

My environment is Windows XP SP2, ActiveRuby 1.8.7.10, Postgresql 8.3.7, pg-0.8.0-x86-mswin32-60.

I attached the reproduction code.

P.S. thank you so much for maintaining a very important library:)

Comments (7)

  1. Michael Granger repo owner
    • changed status to open

    Thanks for the report!

    I probably won't have time to look at this this weekend, which means it probably won't be in the upcoming 0.9.0 release, but if the problem still exists with the new release I'll try to reproduce this.

  2. Lars Kanis

    I'm able to reproduce your issue with OneClickInstaller (ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-mswin32]) and the current hg-head-version of ruby-pg. I coincidentally had a similar problem some years ago and it seems the bug is not fixed till now. Unfortunately, I did not report it to matz.

    As far as i can see, rb_thread_select() in MSVC 6.0 compiled ruby versions is buggy. Maybe other win32-compilations too. The compilation environment of the ruby-pg seems to be unrelevant.

    Attached you can find a patch to work around this bug. Could you please test it in your environment?

  3. shun reporter

    Thank you so much for the patch! It worked very well.

    What happens if a query takes longer than 10 miliseconds?

  4. Lars Kanis

    Postgres should always be fast enough to deliver within 10ms!

    No, you're right. I did a first quick test with pg_sleep(), and it worked. But looking a bit deeper shows, that a second thread acctually is blocked by async_exec().

    So, you can find attached the corrected new patch (based on the current hg-head with the old patch already commited) which should handle longer running querys with broken rb_thread_select(), too. It includes a proper rspec, to prospective ensure that threading works.

  5. Michael Granger repo owner

    A better fix for the PGconn#block weirdness on Win32 (closes #16).

    • Replaced the WIN32 conditionals in PGconn#block with a much simpler solution.
    • Added a few specs to test PGconn#block based on Lars Kanis's proposed one.

    Thanks to both Lars and Shun for all their help with this issue.

    74fab32c2687

  6. Log in to comment