Skip to content

bottleneck lost tracing data when using reservoir options #211

Open
@lingjin666

Description

@lingjin666

Here is my code

import Bottleneck from 'bottleneck';
import { AsyncLocalStorage } from 'async_hooks';

const asyncLocalStorage = new AsyncLocalStorage();

const bottleneck = new Bottleneck({
    reservoir: 3,
    reservoirRefreshInterval: 5000,
    reservoirRefreshAmount: 3,

    maxConcurrent: 1,
    minTime: 1000,
});

const init = async () => {
    const num = 1;
    for (let i = 0; i < 100; i++) {
        await asyncLocalStorage.run(i, async () => {
            await bottleneck.schedule(() => {
                return asyncFun();
            });
        });
    }
};

async function asyncFun() {
    console.log(asyncLocalStorage.getStore());
}

init();

output:

0
1
2
undefined
4
5
undefined
7
8
undefined
10
11
.......

Normally, it will print from 0 to 99. But when meet 3/6/9...., it prints undefined. So why ?

$ node -v    
v18.12.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions