casbin / gorm-adapter

GORM adapter for Casbin, see extended version of GORM Adapter Ex at: https://github.com/casbin/gorm-adapter-ex
https://github.com/casbin/casbin
Apache License 2.0
692 stars 207 forks source link

Provision to close connection created using pgAdapter.NewFilteredAdapter #148

Closed arafat-java closed 2 years ago

arafat-java commented 2 years ago

Ours is a cloud based multi tenant system and we cache one adapter instance (pgAdapter.NewFilteredAdapter) for each tenant. However when we remove the adapter instance from the cache the connection to DB is not released So, how to close connection created using pgAdapter.NewFilteredAdapter

casbin-bot commented 2 years ago

@tangyang9464 @closetool @sagilio

hsluoyz commented 2 years ago

@tangyang9464 @Abingcbc @fabian4

Abingcbc commented 2 years ago

@arafat-java You can use finalizer(a *Adapter) Refer to https://github.com/casbin/gorm-adapter/blob/master/adapter.go#L81

arafat-java commented 2 years ago

@arafat-java You can use finalizer(a *Adapter) Refer to https://github.com/casbin/gorm-adapter/blob/master/adapter.go#L81

How can I call that finalizer(a *Adapter). I have the reference of Adapter that I get via pgAdapter.NewFilteredAdapter. Is there any code sample

hsluoyz commented 2 years ago

@Abingcbc isn't finalizer() a private method? Can it be called from outside?

Abingcbc commented 2 years ago

@Abingcbc isn't finalizer() a private method? Can it be called from outside?

Yes, it's my mistake.

Abingcbc commented 2 years ago

@arafat-java The connection will be closed when the adapter is finalized and released by runtime gc. Do you need to manually close the connection immediately? The current version of the adapter doesn't support but we can add this feature.

hsluoyz commented 2 years ago

@Abingcbc plz add this feature, like adding a Close() method to the adapter.

arafat-java commented 2 years ago

Thanks guys for the quick resolution