my-ship-it commented on code in PR #1797:
URL: https://github.com/apache/cloudberry/pull/1797#discussion_r3346638405
##########
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:
> Where‘s the spinlock? The fault injector code mustn't be called in
critical region. It may invoke error/fatal.
Got it, thanks for explaination.
--
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]