diff --git a/ethdb/mdbx/cursor.go b/ethdb/mdbx/cursor.go index 88a4d15b8..c0f331b48 100644 --- a/ethdb/mdbx/cursor.go +++ b/ethdb/mdbx/cursor.go @@ -7,7 +7,6 @@ package mdbx */ import "C" import ( - "runtime" "unsafe" ) @@ -106,7 +105,6 @@ func (c *Cursor) close() bool { // See mdb_cursor_close. func (c *Cursor) Close() { if c.close() { - runtime.SetFinalizer(c, nil) } } diff --git a/ethdb/mdbx/env.go b/ethdb/mdbx/env.go index d4c575b91..83b40917d 100644 --- a/ethdb/mdbx/env.go +++ b/ethdb/mdbx/env.go @@ -540,19 +540,12 @@ func (env *Env) SetMaxDBs(size int) error { // methods, which assist in management of Txn objects and provide OS thread // locking required for write transactions. // -// A finalizer detects unreachable, live transactions and logs thems to -// standard error. The transactions are aborted, but their presence should be -// interpreted as an application error which should be patched so transactions -// are terminated explicitly. Unterminated transactions can adversly effect +// Unterminated transactions can adversly effect // database performance and cause the database to grow until the map is full. // // See mdbx_txn_begin. func (env *Env) BeginTxn(parent *Txn, flags uint) (*Txn, error) { - txn, err := beginTxn(env, parent, flags) - if txn != nil { - runtime.SetFinalizer(txn, func(v interface{}) { v.(*Txn).finalize() }) - } - return txn, err + return beginTxn(env, parent, flags) } // RunTxn creates a new Txn and calls fn with it as an argument. Run commits diff --git a/ethdb/mdbx/txn.go b/ethdb/mdbx/txn.go index bff0aa389..c132441da 100644 --- a/ethdb/mdbx/txn.go +++ b/ethdb/mdbx/txn.go @@ -9,7 +9,6 @@ import "C" import ( "log" - "runtime" "time" "unsafe" ) @@ -196,7 +195,6 @@ func (txn *Txn) Commit() (CommitLatency, error) { panic("managed transaction cannot be committed directly") } - runtime.SetFinalizer(txn, nil) return txn.commit() } @@ -242,7 +240,6 @@ func (txn *Txn) Abort() { panic("managed transaction cannot be aborted directly") } - runtime.SetFinalizer(txn, nil) txn.abort() } @@ -615,7 +612,6 @@ func (txn *Txn) Del(dbi DBI, key, val []byte) error { func (txn *Txn) OpenCursor(dbi DBI) (*Cursor, error) { cur, err := openCursor(txn, dbi) if cur != nil && txn.readonly { - runtime.SetFinalizer(cur, (*Cursor).close) } return cur, err } diff --git a/ethdb/mdbx/txn_test.go b/ethdb/mdbx/txn_test.go index 17a522252..3ef55915c 100644 --- a/ethdb/mdbx/txn_test.go +++ b/ethdb/mdbx/txn_test.go @@ -9,7 +9,6 @@ import ( "runtime" "syscall" "testing" - "time" ) func TestTxn_ID(t *testing.T) { @@ -100,7 +99,6 @@ func TestTxn_ID(t *testing.T) { } func TestTxn_errLogf(t *testing.T) { - t.Skip("to investigate") env := setup(t) defer clean(env, t) @@ -116,37 +114,6 @@ func TestTxn_errLogf(t *testing.T) { } } -func TestTxn_finalizer(t *testing.T) { - env := setup(t) - defer clean(env, t) - - runtime.LockOSThread() - defer runtime.UnlockOSThread() - - called := make(chan struct{}) - func() { - txn, err := env.BeginTxn(nil, 0) - if err != nil { - t.Error(err) - } else { - txn.errLogf = func(string, ...interface{}) { - close(called) - } - } - }() - - // make sure that finalizer has a chance to get called. it seems like this - // may not be consistent across versions of go. - runtime.GC() - runtime.Gosched() - - select { - case <-called: - case <-time.After(time.Second): - t.Errorf("error logging function was not called") - } -} - func TestTxn_Drop(t *testing.T) { env := setup(t) defer clean(env, t)