Fix pg-0.8.0 infinite loop in async_exec("COPY") infinite loop

Issue #9 resolved
Michael Granger repo owner created an issue

Via Mike Pomraning in [[http://rubyforge.org/tracker/index.php?func=detail&aid=27100&group_id=3214&atid=12398|RubyForge Patch 12390]] (formatting mine):

{{{async_exec("COPY tbl TO STDOUT")}}} hangs in an infinite loop in {{{pgconn_get_last_result()}}}, because the latter function is not aware that certain result status codes, namely {{{PGRES_COPY_OUT}}} and {{{PGRES_COPY_IN}}}, are not meant to be fetched repeatedly. 1

Demonstration:

{{{

!ruby

require 'pg'

conn = PGconn.connect('localhost', 5432, nil, nil, 'postgres', nil, nil) conn.async_exec("COPY (SELECT 1 UNION ALL SELECT 2) TO STDOUT")

data = conn.get_copy_data(true) until data.nil? if false == data conn.block if false == data data = conn.get_copy_data(true) end p data

data = conn.get_copy_data(true)

end }}}

Without patch:

{{{

!console

$ ruby demo.rb (prints nothing -- hangs) }}}

With patch:

{{{

!console

$ ruby demo.rb "1\n" "2\n" }}}

Now, {{{PGRES_EMPTY_QUERY}}} may be another such state, but I've not hit it in nature.

Comments (3)

  1. Log in to comment