cube-js / cube-js/cube

Leaking Timeout In LocalQueueDriver

Open
#4,198 3 comments 0 reactions 0 assignees View on GitHub
good first issue help wanted
Dominant language
Rust
Stars
20.8k
Forks
2.1k
Avg merge
1d 2h
Merged PRs (30d)
181

Description

**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`,

```javascript
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,
},
},
},
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.