mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Retry release to fix flaky tests (#216781)
Related to https://github.com/elastic/kibana/pull/216397 Closes https://github.com/elastic/kibana/issues/216763 This change ensures that we do not send the `release` request and `extendTtl` request simultaneously in `withLock`. This caused a conflict causing tests to fail: ``` └-> "before all" hook for "should return the result of the callback" │ERROR Failed to release lock "my_lock_with_ttl_extension": version_conflict_engine_exception │ Root causes: │ version_conflict_engine_exception: [my_lock_with_ttl_extension]: version conflict, required seqNo [43], primary term [1]. current document has seqNo [44] and primary term [1] ``` Flaky tests: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/8142
This commit is contained in:
parent
9797e95289
commit
7275d2e8bd
1 changed files with 11 additions and 5 deletions
|
@ -285,20 +285,26 @@ export async function withLock<T>(
|
|||
`Lock "${lockId}" acquired. Extending TTL every ${prettyMilliseconds(extendInterval)}`
|
||||
);
|
||||
|
||||
let extendTTlPromise = Promise.resolve(true);
|
||||
const intervalId = setInterval(() => {
|
||||
lockManager.extendTtl().catch((err) => {
|
||||
logger.error(`Failed to extend lock "${lockId}":`, err);
|
||||
});
|
||||
// wait for the previous extendTtl request to finish before sending the next one. This is to avoid flooding ES with extendTtl requests in cases where ES is slow to respond.
|
||||
extendTTlPromise = extendTTlPromise
|
||||
.then(() => lockManager.extendTtl())
|
||||
.catch((err) => {
|
||||
logger.error(`Failed to extend lock "${lockId}":`, err);
|
||||
return false;
|
||||
});
|
||||
}, extendInterval);
|
||||
|
||||
try {
|
||||
return await callback();
|
||||
} finally {
|
||||
clearInterval(intervalId);
|
||||
try {
|
||||
clearInterval(intervalId);
|
||||
await extendTTlPromise;
|
||||
await lockManager.release();
|
||||
} catch (error) {
|
||||
logger.error(`Failed to release lock "${lockId}": ${error.message}`);
|
||||
logger.error(`Failed to release lock "${lockId}" in withLock: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue