devsu / keycloak-nodejs-multirealm

Keycloak NodeJS Multi Realm Adapter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: Cannot assign to read only property 'writeQueueSize' of object '#<TCP>'

techimist opened this issue · comments

Protecting a url fails with the following error.

TypeError: Cannot assign to read only property 'writeQueueSize' of object '#<TCP>'
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:16)
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:18)
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:18)
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:18)
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:18)
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:18)
    at _clone (/Users/techimist/my-project/node_modules/clone/clone.js:162:18)
    at clone (/Users/techimist/my-project/node_modules/clone/clone.js:202:10)
    at NodeCache._wrap (/Users/techimist/my-project/node_modules/node-cache/lib/node_cache.js:674:24)
    at NodeCache.set (/Users/techimist/my-project/node_modules/node-cache/lib/node_cache.js:413:31)

Here is a screenshot of call stack which makes more sense:
Screenshot 2020-05-26 at 3 23 09 AM

node version: v10.19.0

This line sets the new realm config in node-cache.

This works as expected if the session store being used is of type new session.MemoryStore() however it fails if I use redis store - new RedisStore({ client: redisClient });

The object which needs to be stored in node-cache somewhat looks like this:

keykloackObj = {
    authenticated: ƒ authenticated(req)
    config: Config {…}
    deauthenticated: ƒ deauthenticated(req)
    grantManager: GrantManager {…}
    stores: (2) [{…}, SessionStore]
}

There are some TCP attributes which are buried very deep in keykloackObj.stores.SessionStore which cannot be cloned if the sessionStorage is of type Redis (I haven't checked with other storage types.)

You're right, it looks like an issue when using a different store than memory store.

Right now it would be difficult for me to implement a solution, but if you provide a PR, it would be more than welcome.

Probably the solution is simple.... just set the useClones option to false when instantiating node-cache.

I will check and open a PR.
Thank you 😃

Fixed in 1.2.0