Skip to content

Commit a0bb005

Browse files
prevent waitFor callback racing condition
1 parent a7b7252 commit a0bb005

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/wait-for.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ function waitFor(
106106
}
107107

108108
function onDone(error, result) {
109+
if (finished) {
110+
return
111+
}
109112
finished = true
110113
clearTimeout(overallTimeoutTimer)
111114

@@ -134,7 +137,7 @@ function waitFor(
134137
}
135138

136139
function checkCallback() {
137-
if (promiseStatus === 'pending') return
140+
if (finished || promiseStatus === 'pending') return
138141
try {
139142
const result = runWithExpensiveErrorDiagnosticsDisabled(callback)
140143
if (typeof result?.then === 'function') {
@@ -160,6 +163,9 @@ function waitFor(
160163
}
161164

162165
function handleTimeout() {
166+
if (finished) {
167+
return
168+
}
163169
let error
164170
if (lastError) {
165171
error = lastError

0 commit comments

Comments
 (0)