Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win32 asynchronous queries hang on connection error #66

Closed
ged opened this issue Apr 14, 2011 · 6 comments
Closed

Win32 asynchronous queries hang on connection error #66

ged opened this issue Apr 14, 2011 · 6 comments

Comments

@ged
Copy link
Owner

ged commented Apr 14, 2011

Original report by Rafał Bigaj (Bitbucket: rafalbigaj, GitHub: rafalbigaj).


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:

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.

PQConsumeInput result is not interpreted in pgconn_block what makes the waiting loop infinite (PQisBusy returns always TRUE) if connection error occurs

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

@ged
Copy link
Owner Author

ged commented Apr 14, 2011

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Thanks for the patch. I'll look it over this weekend.

@ged
Copy link
Owner Author

ged commented Apr 19, 2011

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


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.

@ged
Copy link
Owner Author

ged commented May 4, 2011

Original comment by Anonymous.


After running into performance problems I found out that the previous patch that added a small wait (1ms) after each PQisBusy is not a good idea. I have committed the next patch:

https://bitbucket.org/rafalbigaj/ruby-pg/changeset/fc4109b2ddba

which uses Winsock events and rb_w32_wait_events.

The proposed solution is faster about 20-30% on WIN32 than the original code.

@ged
Copy link
Owner Author

ged commented May 4, 2011

Original comment by Rafał Bigaj (Bitbucket: rafalbigaj, GitHub: rafalbigaj).


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?

@ged
Copy link
Owner Author

ged commented May 13, 2011

Original comment by Rafał Bigaj (Bitbucket: rafalbigaj, GitHub: rafalbigaj).


One commit more:
https://bitbucket.org/rafalbigaj/ruby-pg/changeset/2bc78e46c1b6
that fixes memory leaks (forgot to close opened event).

@ged
Copy link
Owner Author

ged commented Jun 7, 2011

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


Fixes #66 Win32 asynchronous queries hang on connection error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant