nhost icon indicating copy to clipboard operation
nhost copied to clipboard

Token refreshed each time the JS UI thread is stucked for more than 1 sec

Open quentin-decre opened this issue 3 years ago • 1 comments

What is the problem

I expect the SDK to refresh the token before it will expire, but not so much, because very frequent token refresh can cause deconnexions. But I see that if my main UI thread is stucked for more than 1 second (usecase : can happen with a 200+ elements list, with DOM recycling, even with a good CPU), then the SDK will refresh the token.

Maybe the issue is here ? image

How to reproduce

Just run this code in your console with the network debugger opened, it will calculate PI decimals for 5 seconds. Then you can see that the token is refreshed.

function * generateDigitsOfPi() {
    let q = 1n;
    let r = 180n;
    let t = 60n;
    let i = 2n;
    while (true) {
        let digit = ((i * 27n - 12n) * q + r * 5n) / (t * 5n);
        yield Number(digit);
        let u = i * 3n;
        u = (u + 1n) * 3n * (u + 2n);
        r = u * 10n * (q * (i * 5n - 2n) + r - t * digit);
        q *= 10n * i * (i++ * 2n - 1n);
        t *= u;
    }
}


let iter = generateDigitsOfPi();
let digits = "";
let endAt = Date.now()+1000*5; //5 seconds

do{
    digits += iter.next().value
}while(Date.now() < endAt)

quentin-decre avatar May 17 '22 21:05 quentin-decre

Hello, Can't reproduce with the latest version of the SDK. Could you try and tell me if you're facing the same issue? FYI the one-second timer now checks the interval between two timestamps: the current time and the JWT expiration time. We are not using relative values such as the previous attempt (e.g. increment one second per iteration)

plmercereau avatar Jun 24 '22 10:06 plmercereau

No news, closing for now. Don't hesitate to ping us with additional info and we'll reopen the issue. Thanks!

plmercereau avatar Aug 18 '22 17:08 plmercereau