Win32 asynchronous queries hang on connection error

Rafał Bigaj avatarRafał Bigaj created an issue

I encountered the following problems on win32 system with all version of pg (0.9.0, 0.9.1, 0.10.0, 0.10.1 and 0.11.0) on Ruby 1.9:

  1. During asynchronous queries the CPU usage is 100% - rb_w32_thread_select does not wait any time on foreign socket (not created with ruby socket API). The only way I found to workaround the problem is simple waiting 1ms before each select if the PG is busy.
  2. PQConsumeInput result is not interpreted in pgconn_block what makes the waiting loop infinite (PQisBusy returns always TRUE) if connection error occurs
  3. pgconn_async_exec can block the interpreter for a long time on initial pgconn_get_last_result (pgconn_block is not called before)

I have committed the fixes for above problems to my fork at: https://bitbucket.org/rafalbigaj/ruby-pg/changeset/17a6a01c1725

Comments (9)

  1. Michael Granger

    Applying the patch as-is breaks the build for me:

    ../../../../ext/pg.c:2602:39: error: operator '||' has no right operand
    ../../../../ext/pg.c: In function ‘pgconn_block’:
    ../../../../ext/pg.c:2608: error: ‘zerotime’ undeclared (first use in this function)
    ../../../../ext/pg.c:2608: error: (Each undeclared identifier is reported only once
    ../../../../ext/pg.c:2608: error: for each function it appears in.)
    

    It's likely just a matter of a missing `defined()` at line 2602.

    I'll fix that and get this applied. Do you have a minimal test case that demonstrates the problem? I can probably figure it out myself, but I'm wondering if it's possible to write a test for it, and thought if you already had something you used, I'd have a headstart.

  2. Rafał Bigaj

    I have attached the simple script that I uses to test if the connection problem still exist.

    During the script is running I release my network connection. On the original code I frequently encounter hangs.

    How to write automated test for it?

  3. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.