errinj: introduce delayed injection
With new macro ERROR_INJECT_COUNTDOWN it is possible to delay error
injection by iparam value: injection will be set only after iparam
times the path is executed. For instance:
void
foo(int i)
{
/* 2 is delay counter. */
ERROR_INJECT_COUNTDOWN(ERRINJ_FOO, {
printf("Error injection on %d cycle!\n", i);
});
}
void
boo(void)
{
for (int i = 0; i < 10; ++i)
foo(i);
}
box.error.injection.set('ERRINJ_FOO', 2)
The result is "Error injection on 2 cycle!". This type of error
injection can turn out to be useful to set injection in the middle of
query processing. Imagine following scenario:
void
foo(void)
{
int *fds[10];
for (int i = 0; i < 10; ++i) {
fds[i] = malloc(sizeof(int));
if (fds[i] == NULL)
goto cleanup;
}
cleanup:
free(fds[0]);
}
"cleanup" section obviously contains error and leads to memory leak.
But using means of casual error injection without delay such situation
can't be detected: OOM can be set only for first cycle iteration and in
this particular case no leaks take place.
Reviewed-by:
Vladislav Shpilevoy <vshpilevoi@mail.ru>
Please register or sign in to comment