jwks Failure: Error: socket hang up using jsonwebtoken and jwks-rsa

50 Views Asked by At

It seems jwks-rsa is not caching the keys, I have a below code which is working fine but if I start flooding requests then it throws error jwks Failure: Error: socket hang up

below is the code sample.

const client = jwksClient({
        cache: true,
        jwksUri: url,
        requestHeaders: {},
        timeout: 30000,
});

const key = await client.getSigningKey("token KID");
const pubkey = key.getPublicKey();

jwt.verify(token, pubkey , {
        algorithms: ['RS256'],
        audience: "my-sample-audience",
});

it throws below error while doing performance tests.

jwks Failure: Error: socket hang up
at connResetException (node:internal/errors:720:14)
at TLSSocket.socketCloseListener (node:_http_client:474:25)
at TLSSocket.emit (node:events:529:35)
at node:net:350:12
at TCP.done (node:_tls_wrap:614:7) {code: 'ECONNRESET'} +26ms
0

There are 0 best solutions below