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

Unexpected behavior when calling the same canister function multiple times asynchronously #558

Closed
infu opened this issue Apr 11, 2022 · 2 comments

Comments

@infu
Copy link
Contributor

infu commented Apr 11, 2022

Describe the bug
Unexpected behavior when calling the same canister function multiple times asynchronously.

To Reproduce

await Promise.all(Array(10).fill(0).map(x => {
    return canister.counter_add()
}))

Where canister was created with Agent

Expected behavior
Should call the function 10 times.
Instead, only one call gets through and all 10 function calls receive copies of the 1st result (possibly because of cache or some kind of protection)
if counter_add returns the current count, then we will receive [1,1,1,1,1,1,1,1,1,1]
I stumbled upon that behavior like 3-4 times and I thought the problem was in my canisters or js.

If we add a 1ms delay, it works as expected

await Promise.all(Array(10).fill(0).map(async x => {
    await delay(1);
    return canister.counter_add()
}))

This will result in something like [1,2,5,4,3,6,7,8,9,10]

@nomeata
Copy link
Contributor

nomeata commented Apr 11, 2022

I wonder if the JS agent uses the “nonce” in the IC request to make these requests actually different (if they get the same timestamp in the expiry field). And judging from the recently merged PR #554 the answer is no, and the solution is already on master.

@krpeacock
Copy link
Contributor

The JS Agent now uses nonces by default, so I think that this issue is covered. @infu are you satisfied with the latest implementation?

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

No branches or pull requests

3 participants