<div dir="ltr">Hi Ishii-San<div><br></div><div>The parch works perfect. Many thanks for looking into it.<br><br>Kind regards</div><div>Muhammad Usama</div><div><br><div class="gmail_quote"><div dir="ltr">On Fri, Dec 7, 2018 at 8:20 PM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp">ishii@sraoss.co.jp</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> Hi Usama,<br>
<br>
The essential reason of the hang is, when Pgpool-II tries to read a<br>
command complete message, the query in progress flag was reset by the<br>
proceeding close complete message. Usualy resetting the flag is fine<br>
but in this case since we already had a sync message, the flag should<br>
have not been reset. So my idea is, checking doing extended query flag<br>
while receiving close complete message. If the doing extended query<br>
flag is off, then do not reset the query in progress flag.<br>
<br>
The attached patch works for me. Can you please check?<br>
<br>
Best regards,<br>
--<br>
Tatsuo Ishii<br>
SRA OSS, Inc. Japan<br>
English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
<br>
&gt; Yeah this is tough. Let me think how Pgpool-II can deal with it.<br>
&gt; <br>
&gt; Best regards,<br>
&gt; --<br>
&gt; Tatsuo Ishii<br>
&gt; SRA OSS, Inc. Japan<br>
&gt; English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
&gt; <br>
&gt;&gt; Hi Ishii-San<br>
&gt;&gt; <br>
&gt;&gt; On Fri, Dec 7, 2018 at 6:30 PM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt; wrote:<br>
&gt;&gt; <br>
&gt;&gt;&gt; Hi Usama,<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I think I have found the cause. The transaction in question basically<br>
&gt;&gt;&gt; does these:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; BEGIN<br>
&gt;&gt;&gt; :<br>
&gt;&gt;&gt; (lots of extended query messages)<br>
&gt;&gt;&gt; :<br>
&gt;&gt;&gt; parse(COMMIT)<br>
&gt;&gt;&gt; bind(COMMIT)<br>
&gt;&gt;&gt; execute(COMMIT)<br>
&gt;&gt;&gt; Sync<br>
&gt;&gt;&gt; Close prepared statement (S_14) [1]<br>
&gt;&gt;&gt; Close prepared statement (S_11) [2]<br>
&gt;&gt;&gt; BEGIN &lt;-- hang<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; This message sequence seems to be unusual, because two close<br>
&gt;&gt;&gt; messages[1][2] are issued *after* a sync message (usually extended<br>
&gt;&gt;&gt; query protocol messages sequence including close messages are finished<br>
&gt;&gt;&gt; by a sync message). Pgpool-II expects a command complete message after<br>
&gt;&gt;&gt; the last BEGIN but unfortunately two close messages, which are<br>
&gt;&gt;&gt; responses of [1][2], arrived before it. While processing the close<br>
&gt;&gt;&gt; complete message, Pgpool-II turned off the query-in-progress flag as<br>
&gt;&gt;&gt; shown in the session_context. So read_kind_from_backend tried to read<br>
&gt;&gt;&gt; from node 1, then hangs.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I was able to reproduce the hang by using attached pgproto data<br>
&gt;&gt;&gt; (pgproto.data).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; If the two close message were issued *before* the sync message,<br>
&gt;&gt;&gt; Pgpool-II does not hang. (see attached pgproto2.data).<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt; Thanks for looking into this. This one seems to be a tough one.<br>
&gt;&gt; Apparently the application getting the hang is using the JDBC driver which<br>
&gt;&gt; is sending this<br>
&gt;&gt; unusual message sequence.<br>
&gt;&gt; <br>
&gt;&gt; Thanks<br>
&gt;&gt; Kind Regards<br>
&gt;&gt; Muhammad Usama<br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt; <br>
&gt;&gt;&gt; &gt; Hi Ishii-San<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Please find the attached the debug log and pgpool.conf<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; The output of the stack trace, session context and query context is<br>
&gt;&gt;&gt; &gt; pasted below<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; *--STACK-TRACE--*<br>
&gt;&gt;&gt; &gt; #0  0x00007f3d5d218c53 in __select_nocancel () at<br>
&gt;&gt;&gt; &gt; ../sysdeps/unix/syscall-template.S:81<br>
&gt;&gt;&gt; &gt; #1  0x000000000042e086 in pool_check_fd (cp=cp@entry=0x7f3d5efb43a0) at<br>
&gt;&gt;&gt; &gt; protocol/pool_process_query.c:696<br>
&gt;&gt;&gt; &gt; #2  0x000000000042e356 in pool_check_fd (cp=cp@entry=0x7f3d5efb43a0) at<br>
&gt;&gt;&gt; &gt; protocol/pool_process_query.c:728<br>
&gt;&gt;&gt; &gt; #3  0x000000000045fafc in pool_read (cp=0x7f3d5efb43a0,<br>
&gt;&gt;&gt; &gt; buf=buf@entry=0x7fffbc4830b5,<br>
&gt;&gt;&gt; &gt; len=len@entry=1) at utils/pool_stream.c:166<br>
&gt;&gt;&gt; &gt; #4  0x000000000043303b in read_kind_from_backend<br>
&gt;&gt;&gt; &gt; (frontend=frontend@entry=0x2314e98,<br>
&gt;&gt;&gt; &gt; backend=backend@entry=0x7f3d5efaf750,<br>
&gt;&gt;&gt; &gt; decided_kind=decided_kind@entry=0x7fffbc4834ba<br>
&gt;&gt;&gt; &gt; &quot;D&quot;)<br>
&gt;&gt;&gt; &gt;     at protocol/pool_process_query.c:3379<br>
&gt;&gt;&gt; &gt; #5  0x000000000043f402 in ProcessBackendResponse<br>
&gt;&gt;&gt; &gt; (frontend=frontend@entry=0x2314e98,<br>
&gt;&gt;&gt; &gt; backend=backend@entry=0x7f3d5efaf750, state=state@entry=0x7fffbc483524,<br>
&gt;&gt;&gt; &gt;     num_fields=num_fields@entry=0x7fffbc483522) at<br>
&gt;&gt;&gt; &gt; protocol/pool_proto_modules.c:2663<br>
&gt;&gt;&gt; &gt; #6  0x0000000000431ea7 in pool_process_query (frontend=0x2314e98,<br>
&gt;&gt;&gt; &gt; backend=0x7f3d5efaf750, reset_request=reset_request@entry=0) at<br>
&gt;&gt;&gt; &gt; protocol/pool_process_query.c:320<br>
&gt;&gt;&gt; &gt; #7  0x000000000042cd49 in do_child (fds=fds@entry=0x23134b0) at<br>
&gt;&gt;&gt; &gt; protocol/child.c:388<br>
&gt;&gt;&gt; &gt; #8  0x00000000004090a5 in fork_a_child (fds=0x23134b0, id=0) at<br>
&gt;&gt;&gt; &gt; main/pgpool_main.c:659<br>
&gt;&gt;&gt; &gt; #9  0x000000000040fb73 in PgpoolMain (discard_status=discard_status@entry<br>
&gt;&gt;&gt; =0<br>
&gt;&gt;&gt; &gt; &#39;\000&#39;, clear_memcache_oidmaps=clear_memcache_oidmaps@entry=0 &#39;\000&#39;) at<br>
&gt;&gt;&gt; &gt; main/pgpool_main.c:378<br>
&gt;&gt;&gt; &gt; #10 0x0000000000407777 in main (argc=&lt;optimized out&gt;, argv=&lt;optimized<br>
&gt;&gt;&gt; out&gt;)<br>
&gt;&gt;&gt; &gt; at main/main.c:349<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; *--SESSION CONTEXT--*<br>
&gt;&gt;&gt; &gt; (gdb) print *session_context<br>
&gt;&gt;&gt; &gt; $4 = {process_context = 0x77c260 &lt;process_context_d&gt;, frontend =<br>
&gt;&gt;&gt; 0x2314e98,<br>
&gt;&gt;&gt; &gt; backend = 0x7f3d5efaf750, in_progress = 0 &#39;\000&#39;,<br>
&gt;&gt;&gt; &gt; doing_extended_query_message = 0 &#39;\000&#39;,<br>
&gt;&gt;&gt; &gt;   need_to_restore_where_to_send = 0 &#39;\000&#39;, where_to_send_save = &quot;\001&quot;,<br>
&gt;&gt;&gt; &gt; &#39;\000&#39; &lt;repeats 126 times&gt;, command_success = 1 &#39;\001&#39;,<br>
&gt;&gt;&gt; writing_transaction<br>
&gt;&gt;&gt; &gt; = 0 &#39;\000&#39;,<br>
&gt;&gt;&gt; &gt;   failed_transaction = 0 &#39;\000&#39;, skip_reading_from_backends = 0 &#39;\000&#39;,<br>
&gt;&gt;&gt; &gt; ignore_till_sync = 0 &#39;\000&#39;, transaction_isolation = POOL_UNKNOWN,<br>
&gt;&gt;&gt; &gt; query_context = 0x248d418,<br>
&gt;&gt;&gt; &gt;   memory_context = 0x22f2558, uncompleted_message = 0x231aeb8,<br>
&gt;&gt;&gt; message_list<br>
&gt;&gt;&gt; &gt; = {capacity = 64, size = 63, sent_messages = 0x2351f70},<br>
&gt;&gt;&gt; &gt; load_balance_node_id = 0,<br>
&gt;&gt;&gt; &gt;   mismatch_ntuples = 0 &#39;\000&#39;, ntuples = {0, -1, 0 &lt;repeats 126 times&gt;},<br>
&gt;&gt;&gt; &gt; reset_context = 0 &#39;\000&#39;, query_cache_array = 0x0, num_selects = 0,<br>
&gt;&gt;&gt; &gt; pending_messages = 0x231b020,<br>
&gt;&gt;&gt; &gt;   previous_message_exists = 0 &#39;\000&#39;, previous_message = {type =<br>
&gt;&gt;&gt; &gt; POOL_EXECUTE, contents = 0x24704f0 &quot;SS_13&quot;, contents_len = 5, query =<br>
&gt;&gt;&gt; &gt; &quot;COMMIT&quot;, &#39;\000&#39; &lt;repeats 1017 times&gt;,<br>
&gt;&gt;&gt; &gt;     statement = &quot;\000_46&quot;, &#39;\000&#39; &lt;repeats 123 times&gt;, portal = &#39;\000&#39;<br>
&gt;&gt;&gt; &gt; &lt;repeats 127 times&gt;, is_rows_returned = 0 &#39;\000&#39;,<br>
&gt;&gt;&gt; not_forward_to_frontend =<br>
&gt;&gt;&gt; &gt; 0 &#39;\000&#39;, node_ids = {0, -1},<br>
&gt;&gt;&gt; &gt;     query_context = 0x242ff68}, major = 3, minor = 0}<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; *--QEURY-TRACE--*<br>
&gt;&gt;&gt; &gt; (gdb) print *session_context-&gt;query_context<br>
&gt;&gt;&gt; &gt; $5 = {original_query = 0x248e0e8 &quot;BEGIN&quot;, rewritten_query = 0x0,<br>
&gt;&gt;&gt; &gt; original_length = 6, rewritten_length = -1, parse_tree = 0x248e038,<br>
&gt;&gt;&gt; &gt; rewritten_parse_tree = 0x0,<br>
&gt;&gt;&gt; &gt;   where_to_send = &quot;\001&quot;, &#39;\000&#39; &lt;repeats 126 times&gt;,<br>
&gt;&gt;&gt; &gt; virtual_master_node_id = 0, query_state = {POOL_UNPARSED &lt;repeats 128<br>
&gt;&gt;&gt; &gt; times&gt;}, is_cache_safe = 0 &#39;\000&#39;, temp_cache = 0x0,<br>
&gt;&gt;&gt; &gt;   is_multi_statement = 0 &#39;\000&#39;, dboid = 0, query_w_hex = 0x0,<br>
&gt;&gt;&gt; &gt; is_parse_error = 0 &#39;\000&#39;, num_original_params = -1,<br>
&gt;&gt;&gt; &gt; pg_terminate_backend_conn = 0x0, skip_cache_commit = 0 &#39;\000&#39;,<br>
&gt;&gt;&gt; &gt;   memory_context = 0x7f3d5efbff20}<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; Thanks<br>
&gt;&gt;&gt; &gt; Best Regards<br>
&gt;&gt;&gt; &gt; Muhammad Usama<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt; On Fri, Dec 7, 2018 at 3:49 AM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt; wrote:<br>
&gt;&gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; Hi Usama,<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; I need:<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; - exact Pgpool-II version<br>
&gt;&gt;&gt; &gt;&gt; - pgpool.conf<br>
&gt;&gt;&gt; &gt;&gt; - gdb print command result of *pool_session_context when Pgpool-II hangs<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Also a full debug log will be helpful.<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; Best regards,<br>
&gt;&gt;&gt; &gt;&gt; --<br>
&gt;&gt;&gt; &gt;&gt; Tatsuo Ishii<br>
&gt;&gt;&gt; &gt;&gt; SRA OSS, Inc. Japan<br>
&gt;&gt;&gt; &gt;&gt; English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt;&gt;&gt; &gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Hi Ishii San<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Thanks for looking into this, As discussed over the call please find<br>
&gt;&gt;&gt; the<br>
&gt;&gt;&gt; &gt;&gt; &gt; attached pgpool log and stack trace for the stuck issue.<br>
&gt;&gt;&gt; &gt;&gt; &gt; I am currently not able to trim down the test case so sorry for<br>
&gt;&gt;&gt; throwing<br>
&gt;&gt;&gt; &gt;&gt; a<br>
&gt;&gt;&gt; &gt;&gt; &gt; huge log file.<br>
&gt;&gt;&gt; &gt;&gt; &gt; There is no special configuration on PostgreSQL server side and this<br>
&gt;&gt;&gt; &gt;&gt; issue<br>
&gt;&gt;&gt; &gt;&gt; &gt; only happens when the load balance node and the primary node are same<br>
&gt;&gt;&gt; &gt;&gt; &gt; and as you can see from the stack trace the stuck happens in the<br>
&gt;&gt;&gt; &gt;&gt; &gt; read_kind_from_backend() function and the reason for that is<br>
&gt;&gt;&gt; &gt;&gt; &gt; the function is trying to read response from the backend node<br>
&gt;&gt;&gt; 1(standby)<br>
&gt;&gt;&gt; &gt;&gt; &gt; while it has only sent the query to the backend node 0 (primary)<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; --stack-trace--<br>
&gt;&gt;&gt; &gt;&gt; &gt; #0  0x00007f1775216c53 in __select_nocancel () at<br>
&gt;&gt;&gt; &gt;&gt; &gt; ../sysdeps/unix/syscall-template.S:81<br>
&gt;&gt;&gt; &gt;&gt; &gt; #1  0x000000000042def6 in pool_check_fd (cp=cp@entry=0x7f1776fb2328)<br>
&gt;&gt;&gt; at<br>
&gt;&gt;&gt; &gt;&gt; &gt; protocol/pool_process_query.c:696<br>
&gt;&gt;&gt; &gt;&gt; &gt; #2  0x000000000042e1c6 in pool_check_fd (cp=cp@entry=0x7f1776fb2328)<br>
&gt;&gt;&gt; at<br>
&gt;&gt;&gt; &gt;&gt; &gt; protocol/pool_process_query.c:728<br>
&gt;&gt;&gt; &gt;&gt; &gt; #3  0x000000000045f92c in pool_read (cp=0x7f1776fb2328,<br>
&gt;&gt;&gt; &gt;&gt; &gt; buf=buf@entry=0x7ffebb5f2345,<br>
&gt;&gt;&gt; &gt;&gt; &gt; len=len@entry=1) at utils/pool_stream.c:166<br>
&gt;&gt;&gt; &gt;&gt; &gt; #4  0x0000000000432eab in read_kind_from_backend<br>
&gt;&gt;&gt; &gt;&gt; &gt; (frontend=frontend@entry=0x2292e88,<br>
&gt;&gt;&gt; &gt;&gt; &gt; backend=backend@entry=0x7f1776fad6d8,<br>
&gt;&gt;&gt; &gt;&gt; &gt; decided_kind=decided_kind@entry=0x7ffebb5f274a<br>
&gt;&gt;&gt; &gt;&gt; &gt; &quot;D&quot;)<br>
&gt;&gt;&gt; &gt;&gt; &gt;     at protocol/pool_process_query.c:3379<br>
&gt;&gt;&gt; &gt;&gt; &gt; #5  0x000000000043f232 in ProcessBackendResponse<br>
&gt;&gt;&gt; &gt;&gt; &gt; (frontend=frontend@entry=0x2292e88,<br>
&gt;&gt;&gt; &gt;&gt; &gt; backend=backend@entry=0x7f1776fad6d8, state=state@entry<br>
&gt;&gt;&gt; =0x7ffebb5f27b4,<br>
&gt;&gt;&gt; &gt;&gt; &gt;     num_fields=num_fields@entry=0x7ffebb5f27b2) at<br>
&gt;&gt;&gt; &gt;&gt; &gt; protocol/pool_proto_modules.c:2653<br>
&gt;&gt;&gt; &gt;&gt; &gt; #6  0x0000000000431d17 in pool_process_query (frontend=0x2292e88,<br>
&gt;&gt;&gt; &gt;&gt; &gt; backend=0x7f1776fad6d8, reset_request=reset_request@entry=0) at<br>
&gt;&gt;&gt; &gt;&gt; &gt; protocol/pool_process_query.c:320<br>
&gt;&gt;&gt; &gt;&gt; &gt; #7  0x000000000042cbb9 in do_child (fds=fds@entry=0x2291370) at<br>
&gt;&gt;&gt; &gt;&gt; &gt; protocol/child.c:387<br>
&gt;&gt;&gt; &gt;&gt; &gt; #8  0x00000000004090a5 in fork_a_child (fds=0x2291370, id=2) at<br>
&gt;&gt;&gt; &gt;&gt; &gt; main/pgpool_main.c:659<br>
&gt;&gt;&gt; &gt;&gt; &gt; #9  0x000000000040fb73 in PgpoolMain<br>
&gt;&gt;&gt; (discard_status=discard_status@entry<br>
&gt;&gt;&gt; &gt;&gt; =0<br>
&gt;&gt;&gt; &gt;&gt; &gt; &#39;\000&#39;, clear_memcache_oidmaps=clear_memcache_oidmaps@entry=0<br>
&gt;&gt;&gt; &#39;\000&#39;) at<br>
&gt;&gt;&gt; &gt;&gt; &gt; main/pgpool_main.c:378<br>
&gt;&gt;&gt; &gt;&gt; &gt; #10 0x0000000000407777 in main (argc=&lt;optimized out&gt;, argv=&lt;optimized<br>
&gt;&gt;&gt; &gt;&gt; out&gt;)<br>
&gt;&gt;&gt; &gt;&gt; &gt; at main/main.c:361<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; Thanks<br>
&gt;&gt;&gt; &gt;&gt; &gt; Best Regards<br>
&gt;&gt;&gt; &gt;&gt; &gt; Muhammad Usama<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt; On Thu, Dec 6, 2018 at 3:52 AM Tatsuo Ishii &lt;<a href="mailto:ishii@sraoss.co.jp" target="_blank">ishii@sraoss.co.jp</a>&gt;<br>
&gt;&gt;&gt; wrote:<br>
&gt;&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; Hi Ishii San<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; I was investigating the issue faced by one of Pgpool-II user who<br>
&gt;&gt;&gt; &gt;&gt; reported<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; that after executing a certain transaction (large amount of data<br>
&gt;&gt;&gt; &gt;&gt; DELETE /<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; INSERT / UPDATE, COMMIT), the next execution of the BEGIN statement<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; hangs(using the extended query protocol).<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; I think the problem is in<br>
&gt;&gt;&gt; pool_is_node_to_be_sent_in_current_query()<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; function. The issue is in streaming replication mode, when<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; pool_is_query_in_progress is not set, the function always returns<br>
&gt;&gt;&gt; &gt;&gt; true.<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; Now<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; consider that we have two backend servers 1 primary and one<br>
&gt;&gt;&gt; standby.<br>
&gt;&gt;&gt; &gt;&gt; And<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; for a particular session the primary node gets selected as a load<br>
&gt;&gt;&gt; &gt;&gt; balance<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; node. So effectively that session should only be sending queries<br>
&gt;&gt;&gt; and<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; reading responses from primary server alone. But with the current<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; implementation of pool_is_node_to_be_sent_in_current_query() the<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; VALID_BACKEND macro will return true for standby node as well when<br>
&gt;&gt;&gt; the<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; query in progress flag is not set(which is wrong when standby node<br>
&gt;&gt;&gt; is<br>
&gt;&gt;&gt; &gt;&gt; not<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; selected for load balancing). and if this happens in let say<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; read_kind_from_backend() function we will get a stuck, since the<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; read_kind_from_backend() will be trying to read the response from<br>
&gt;&gt;&gt; &gt;&gt; standby<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; node while we have never sent any query to that node.<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; Can you please take a look at the attached patch, I am not sure if<br>
&gt;&gt;&gt; it<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; will<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; &gt; have some side effects or not.<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; Unfortunately the patch would not help and probably would break many<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; cases which are working today.<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; For the scenario you mentioned is already handled by<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; pool_pending_message_* functions defined in<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; context/query_context.c. When a message, for example parse, is sent<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; from frontend and forwarded to backends, the info is recorded in an<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; FIFO queue by pool_pending_message_add() along with info which of<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; backend the message is forwarded to. When the parse message will be<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; replied back with &quot;parse complete message&quot; from the backend,<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; read_kind_message_from_backend() can know from which of backend it<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; should read a message by looking at the head of the queue.  Once the<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; message is retrieved (in this example parse complete message), an<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; entry in the queue (in this example parse message) is pulled out and<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; removed.<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; This mechanism usually works well unless backend sends unpredicted<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; message. Recently one of such a case was reported:<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; <a href="https://www.pgpool.net/mantisbt/view.php?id=448" rel="noreferrer" target="_blank">https://www.pgpool.net/mantisbt/view.php?id=448</a><br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; In the report PostgreSQL sends an error message caused by<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; idle_in_transaction_timeout setting which Pgpool-II does not expect.<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; Does the user has any uncommon setting in postgresql.conf?<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; Best regards,<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; --<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; Tatsuo Ishii<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; SRA OSS, Inc. Japan<br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; English: <a href="http://www.sraoss.co.jp/index_en.php" rel="noreferrer" target="_blank">http://www.sraoss.co.jp/index_en.php</a><br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt; Japanese:<a href="http://www.sraoss.co.jp" rel="noreferrer" target="_blank">http://www.sraoss.co.jp</a><br>
&gt;&gt;&gt; &gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt; &gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt; _______________________________________________<br>
&gt; pgpool-hackers mailing list<br>
&gt; <a href="mailto:pgpool-hackers@pgpool.net" target="_blank">pgpool-hackers@pgpool.net</a><br>
&gt; <a href="http://www.pgpool.net/mailman/listinfo/pgpool-hackers" rel="noreferrer" target="_blank">http://www.pgpool.net/mailman/listinfo/pgpool-hackers</a><br>
</blockquote></div></div></div>