@@ -481,7 +481,8 @@ pg_query_state(PG_FUNCTION_ARGS)
481481 shm_mq_msg * msg ;
482482 List * bg_worker_procs = NIL ;
483483 List * msgs ;
484- int i ;
484+ instr_time start_time ;
485+ instr_time cur_time ;
485486
486487 if (!module_initialized )
487488 ereport (ERROR , (errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
@@ -514,14 +515,22 @@ pg_query_state(PG_FUNCTION_ARGS)
514515 init_lock_tag (& tag , PG_QUERY_STATE_KEY );
515516 LockAcquire (& tag , ExclusiveLock , false, false);
516517
517- for (i = 0 ; pg_atomic_read_u32 (& counterpart_userid -> n_peers ) != 0 && i <= MAX_TIMEOUT /1000 ; i ++ )
518+ INSTR_TIME_SET_CURRENT (start_time );
519+
520+ while (pg_atomic_read_u32 (& counterpart_userid -> n_peers ) != 0 )
518521 {
519522 pg_usleep (1000000 ); /* wait one second */
520523 CHECK_FOR_INTERRUPTS ();
521- }
522- if (i > MAX_TIMEOUT /1000 )
523- elog (WARNING , "pg_query_state: last request was interrupted" );
524524
525+ INSTR_TIME_SET_CURRENT (cur_time );
526+ INSTR_TIME_SUBTRACT (cur_time , start_time );
527+
528+ if (INSTR_TIME_GET_MILLISEC (cur_time ) > MAX_RCV_TIMEOUT )
529+ {
530+ elog (WARNING , "pg_query_state: last request was interrupted" );
531+ break ;
532+ }
533+ }
525534 pg_atomic_write_u32 (& counterpart_userid -> n_peers , 1 );
526535
527536 counterpart_user_id = GetRemoteBackendUserId (proc );
@@ -1023,7 +1032,7 @@ GetRemoteBackendQueryStates(PGPROC *leader,
10231032 mq_receive_result = shm_mq_receive_with_timeout (mqh ,
10241033 & len ,
10251034 (void * * ) & msg ,
1026- MAX_TIMEOUT );
1035+ MAX_RCV_TIMEOUT );
10271036 if (mq_receive_result != SHM_MQ_SUCCESS )
10281037 /* counterpart is died, not consider it */
10291038 continue ;
0 commit comments