@@ -6299,6 +6299,9 @@ threadRun(void *arg)
62996299 int nsocks ; /* number of sockets to be waited for */
63006300 int64 min_usec ;
63016301 int64 now_usec = 0 ; /* set this only if needed */
6302+ bool buffered_rx = false; /* true if some of the clients has
6303+ * data left in SSL/ZPQ read
6304+ * buffers */
63026305
63036306 /*
63046307 * identify which client sockets should be checked for input, and
@@ -6339,6 +6342,9 @@ threadRun(void *arg)
63396342 */
63406343 int sock = PQsocket (st -> con );
63416344
6345+ /* check if conn has buffered SSL / ZPQ read data */
6346+ buffered_rx = buffered_rx || PQreadPending (st -> con );
6347+
63426348 if (sock < 0 )
63436349 {
63446350 pg_log_error ("invalid socket: %s" , PQerrorMessage (st -> con ));
@@ -6389,7 +6395,7 @@ threadRun(void *arg)
63896395 {
63906396 if (nsocks > 0 )
63916397 {
6392- rc = wait_on_socket_set (sockets , min_usec );
6398+ rc = buffered_rx ? 1 : wait_on_socket_set (sockets , min_usec );
63936399 }
63946400 else /* nothing active, simple sleep */
63956401 {
@@ -6398,7 +6404,7 @@ threadRun(void *arg)
63986404 }
63996405 else /* no explicit delay, wait without timeout */
64006406 {
6401- rc = wait_on_socket_set (sockets , 0 );
6407+ rc = buffered_rx ? 1 : wait_on_socket_set (sockets , 0 );
64026408 }
64036409
64046410 if (rc < 0 )
@@ -6437,8 +6443,11 @@ threadRun(void *arg)
64376443 pg_log_error ("invalid socket: %s" , PQerrorMessage (st -> con ));
64386444 goto done ;
64396445 }
6440-
6441- if (!socket_has_input (sockets , sock , nsocks ++ ))
6446+ if (PQreadPending (st -> con ))
6447+ {
6448+ nsocks ++ ;
6449+ }
6450+ else if (!socket_has_input (sockets , sock , nsocks ++ ))
64426451 continue ;
64436452 }
64446453 else if (st -> state == CSTATE_FINISHED ||
0 commit comments