casbin / mongodb-adapter

MongoDB adapter for Casbin

Home Page:https://github.com/casbin/casbin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

failed to use global session when cached socket is closed

levimm opened this issue · comments

commented

I'm using this mongo adapter for a while and sometimes when network is reconnect, I got "Closed explicitly" error.
After digging in, I find this adapter using the global session to do all the operation. When the cache socket is closed, it won't restore the session.
I'd like to create a pr to fix this issue. There're two solutions. First continues using this global session but checks session status in a goroutine to refresh it. Second uses session.Copy() for all db operation. Not sure which one is better. Any advise?

Hi @levimm , why not rebuild the connection if the socket is closed? I mean if the socket is found closed, there would be an error, then we reconnect to get the session back. I think this way works the best?

commented

@hsluoyz Could you check the pr #17 . It doesn't need to handle the different cases of error and add the retry logic. A few more sockets will be used but they'll be closed eventually.

I have encountered the same problem that my adapter will fail to load policy after I restart my MongoDB. @hsluoyz @levimm

I have encountered the same problem that my adapter will fail to load policy after I restart my MongoDB. @hsluoyz @levimm

I use the synced enforcer to reload automatically.

Merged.

@tokingHong In that issue (casbin/casbin#191), I asked about a minimized working example, not still not provided yet.

This issue can be closed now.