diff --git a/internal/datastore/common/tuple.go b/internal/datastore/common/tuple.go index 854b84d705..492c14ce09 100644 --- a/internal/datastore/common/tuple.go +++ b/internal/datastore/common/tuple.go @@ -1,17 +1,16 @@ package common import ( - "runtime" - "github.com/authzed/spicedb/pkg/datastore" "github.com/authzed/spicedb/pkg/datastore/options" core "github.com/authzed/spicedb/pkg/proto/core/v1" + "github.com/authzed/spicedb/pkg/spiceerrors" ) // NewSliceRelationshipIterator creates a datastore.TupleIterator instance from a materialized slice of tuples. func NewSliceRelationshipIterator(tuples []*core.RelationTuple, order options.SortOrder) datastore.RelationshipIterator { iter := &sliceRelationshipIterator{tuples: tuples, order: order} - runtime.SetFinalizer(iter, MustIteratorBeClosed) + spiceerrors.SetFinalizerForDebugging(iter, MustIteratorBeClosed) return iter } diff --git a/internal/datastore/memdb/readonly.go b/internal/datastore/memdb/readonly.go index 69cfdbecde..76790f62e8 100644 --- a/internal/datastore/memdb/readonly.go +++ b/internal/datastore/memdb/readonly.go @@ -3,7 +3,6 @@ package memdb import ( "context" "fmt" - "runtime" "slices" "sort" "strings" @@ -524,7 +523,7 @@ func eq(lhsNamespace, lhsObjectID, lhsRelation string, rhs *core.ObjectAndRelati func newMemdbTupleIterator(it memdb.ResultIterator, limit *uint64, order options.SortOrder) *memdbTupleIterator { iter := &memdbTupleIterator{it: it, limit: limit, order: order} - runtime.SetFinalizer(iter, mustHaveBeenClosed) + spiceerrors.SetFinalizerForDebugging(iter, mustHaveBeenClosed) return iter } diff --git a/pkg/spiceerrors/assert_off.go b/pkg/spiceerrors/assert_off.go index c1ecd29c94..d537c77625 100644 --- a/pkg/spiceerrors/assert_off.go +++ b/pkg/spiceerrors/assert_off.go @@ -7,3 +7,8 @@ package spiceerrors func DebugAssert(condition func() bool, format string, args ...any) { // Do nothing on purpose } + +// SetFinalizerForDebugging is a no-op in non-CI builds +func SetFinalizerForDebugging[T any](obj interface{}, finalizer func(obj T)) { + // Do nothing on purpose +} diff --git a/pkg/spiceerrors/assert_on.go b/pkg/spiceerrors/assert_on.go index 6b90a605c6..d64ec7d333 100644 --- a/pkg/spiceerrors/assert_on.go +++ b/pkg/spiceerrors/assert_on.go @@ -3,7 +3,10 @@ package spiceerrors -import "fmt" +import ( + "fmt" + "runtime" +) // DebugAssert panics if the condition is false in CI builds. func DebugAssert(condition func() bool, format string, args ...any) { @@ -11,3 +14,9 @@ func DebugAssert(condition func() bool, format string, args ...any) { panic(fmt.Sprintf(format, args...)) } } + +// SetFinalizerForDebugging sets a finalizer on the object for debugging purposes +// in CI builds. +func SetFinalizerForDebugging[T any](obj interface{}, finalizer func(obj T)) { + runtime.SetFinalizer(obj, finalizer) +}