cube-js/cube

Leaking Timeout In LocalQueueDriver

Open

#4,198 创建于 2022年3月10日

在 GitHub 查看
 (3 评论) (0 反应) (0 负责人)Rust (1,965 fork)batch import
good first issuehelp wanted

仓库指标

Star
 (19,563 star)
PR 合并指标
 (平均合并 5天 16小时) (30 天内合并 138 个 PR)

描述

Describe the bug The LocalQueueDriver leaks setTimeout in a Promise.race.

To Reproduce Steps to reproduce the behavior:

  1. Set continueWaitTimeout to a high number, 20+ seconds or so.
  2. Make a load request to Cubejs
  3. Call shutdown on the server.
  4. Process runs until timeout ends.

Expected behavior Timeout should be canceled if nothing is awaiting it.

In LocalQueueDriver.js,

 async getResultBlocking(queryKey) {
    const resultListKey = this.resultListKey(queryKey);
    if (!this.queryDef[this.redisHash(queryKey)] && !this.resultPromises[resultListKey]) {
      return null;
    }

    const timeoutPromise = (timeout) => new Promise((resolve) => setTimeout(() => resolve(null), timeout));

    const res = await Promise.race([
      this.getResultPromise(resultListKey),

      // LEAKING TIMEOUT HERE

      timeoutPromise(this.continueWaitTimeout * 1000),
    ]);

    if (res) {
      delete this.resultPromises[resultListKey];
    }
    return res;

** Example Config **

    orchestratorOptions: {
      queryCacheOptions: {
        queueOptions: {
          continueWaitTimeout: 30,
        },
      },
    },

贡献者指南