This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-mongodb-adapter.git
The following commit(s) were added to refs/heads/master by this push:
new 857d4ee fix: don't disconnect the client passed to NewAdapterByDB
857d4ee is described below
commit 857d4eec83d6d900512f93c31e7a2dd53e7a09f9
Author: Yang Luo <[email protected]>
AuthorDate: Thu Nov 5 01:14:43 2026 +0800
fix: don't disconnect the client passed to NewAdapterByDB
---
adapter.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/adapter.go b/adapter.go
index 5afd9a9..bacb1a2 100644
--- a/adapter.go
+++ b/adapter.go
@@ -143,6 +143,8 @@ type AdapterConfig struct {
IsFiltered bool
}
+// NewAdapterByDB creates an adapter using an existing client. The client stays
+// owned by the caller and is never disconnected by the adapter.
func NewAdapterByDB(client *mongo.Client, config *AdapterConfig)
(persist.BatchAdapter, error) {
if config == nil {
config = &AdapterConfig{}
@@ -170,9 +172,6 @@ func NewAdapterByDB(client *mongo.Client, config
*AdapterConfig) (persist.BatchA
return nil, err
}
- // Call the destructor when the object is released.
- runtime.SetFinalizer(a, finalizer)
-
return a, nil
}
@@ -189,6 +188,7 @@ func (a *adapter) open(clientOption *options.ClientOptions,
databaseName string,
a.collection = collection
if err = a.prepareIndexes(); err != nil {
+ a.close()
return err
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]