Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

waitFor does not properly cancel #174

Closed
1 of 3 tasks
s1hofmann opened this issue Oct 21, 2020 · 1 comment · Fixed by #177
Closed
1 of 3 tasks

waitFor does not properly cancel #174

s1hofmann opened this issue Oct 21, 2020 · 1 comment · Fixed by #177
Assignees

Comments

@s1hofmann
Copy link
Member

Version
1.5.0

Short overview
Extracted from #173

Issue occurs on

  • Virtual machine
  • Docker container
  • Dev/Host system

Detailed error description

I was trying to debug this case to find the cause, I did not find it but found another related bug with screen.waitFor, the waitFor uses this utility, which does not clear the interval correctly if the max timeout is reached before getting the result of the action().

this is the flow:

maybe something similar is happening in the files related to the OpenCV

Steps to reproduce error

Additional content

Please provide any (mandatory) additional data to reproduce the error (Dockerfiles etc.)

here is basically the code needed to fix this case in util/poll-action.function.ts, not sure if you want me to send a PR

export function timeout<R>(updateIntervalMs: number, maxDurationMs: number, action: (...params: any) => Promise<R>): Promise<R> {
  return new Promise<R>((resolve, reject) => {
    let interval: NodeJS.Timeout;
    let isDone = false;
    const maxTimeout = setTimeout(
      () => {
        isDone = true;
        clearTimeout(maxTimeout);
        if (interval) {
          clearTimeout(interval);
        }
        reject(`Action timed out after ${maxDurationMs} ms`);
      },
      maxDurationMs
    );
    const startInterval = () => {
      interval = setTimeout(function intervalFunc() {
        action().then((result) => {
          if (isDone) {
            return;
          }

          if (!result) {
            interval = setTimeout(intervalFunc, updateIntervalMs);
          } else {
            isDone = true;
            clearTimeout(maxTimeout);
            clearTimeout(interval);
            resolve(result);
          }
        }).catch(() => {
          if (isDone) {
            return;
          }

          interval = setTimeout(intervalFunc, updateIntervalMs);
        });
      }, updateIntervalMs);
    };

    action().then((result) => {
      if (isDone) {
        return;
      }

      if (!result) {
        startInterval();
      } else {
        isDone = true;
        clearTimeout(maxTimeout);
        resolve(result);
      }
    }).catch(() => {
      if (isDone) {
        return;
      }

      startInterval();
    });
  });
}
@svettwer
Copy link
Contributor

svettwer commented Nov 6, 2020

I'll take care of this. 👍

svettwer added a commit that referenced this issue Nov 9, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
…n cleaned up
svettwer added a commit that referenced this issue Nov 10, 2020
…ly-cancel

(#174) Cancel interval timer creation
svettwer added a commit that referenced this issue Nov 10, 2020
(#174) Added timer tolerance to stabilize CI pipeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants