my-ship-it commented on code in PR #1797:
URL: https://github.com/apache/cloudberry/pull/1797#discussion_r3345625675


##########
src/backend/utils/misc/faultinjector.c:
##########
@@ -402,14 +403,41 @@ FaultInjector_InjectFaultIfSet_out_of_line(
                        break;
 
                case FaultInjectorTypeSleep:
-                       ereport(LOG,
-                                       (errcode(ERRCODE_FAULT_INJECT),
-                                        errmsg("fault triggered, fault 
name:'%s' fault type:'%s' ",
-                                                       entryLocal->faultName,
-                                                       
FaultInjectorTypeEnumToString[entryLocal->faultInjectorType])));        
-                       
-                       pg_usleep(entryLocal->extraArg * 1000000L);
-                       break;
+                       {
+                               struct timeval start;
+                               int64           total_us = (int64) 
entryLocal->extraArg * 1000000L;
+                               int64           elapsed_us = 0;
+
+                               ereport(LOG,
+                                               (errcode(ERRCODE_FAULT_INJECT),
+                                                errmsg("fault triggered, fault 
name:'%s' fault type:'%s' ",
+                                                               
entryLocal->faultName,
+                                                               
FaultInjectorTypeEnumToString[entryLocal->faultInjectorType])));
+
+                               /*
+                                * pg_usleep() is a single select() and returns 
early on any
+                                * signal (e.g. SIGALRM from a registered 
timeout such as
+                                * GP_PARALLEL_RETRIEVE_CURSOR_CHECK_TIMEOUT). 
A bare call
+                                * therefore can't guarantee the requested 
duration, which
+                                * defeats the purpose of fault-injection 
'sleep' (tests
+                                * rely on it as a deterministic blocking 
window). Loop on
+                                * the wallclock until the requested time has 
fully elapsed.
+                                * A genuine cancel (SIGINT) or termination 
still aborts the
+                                * sleep via CHECK_FOR_INTERRUPTS.
+                                */
+                               gettimeofday(&start, NULL);
+                               while (elapsed_us < total_us)
+                               {
+                                       struct timeval now;
+
+                                       pg_usleep(total_us - elapsed_us);
+                                       CHECK_FOR_INTERRUPTS();

Review Comment:
   Not sure if it is safe to call CHECK_FOR_INTERRUPTS here in spinlock context?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to