diff --git a/hscontrol/app.go b/hscontrol/app.go index 095f1c2c145..cd80bc9978f 100644 --- a/hscontrol/app.go +++ b/hscontrol/app.go @@ -225,7 +225,7 @@ func (h *Headscale) deleteExpireEphemeralNodes(milliSeconds int64) { for range ticker.C { var removed []types.NodeID var changed []types.NodeID - if err := h.db.DB.Transaction(func(tx *gorm.DB) error { + if err := h.db.Write(func(tx *gorm.DB) error { removed, changed = db.DeleteExpiredEphemeralNodes(tx, h.cfg.EphemeralNodeInactivityTimeout) return nil @@ -263,7 +263,7 @@ func (h *Headscale) expireExpiredMachines(intervalMs int64) { var changed bool for range ticker.C { - if err := h.db.DB.Transaction(func(tx *gorm.DB) error { + if err := h.db.Write(func(tx *gorm.DB) error { lastCheck, update, changed = db.ExpireExpiredNodes(tx, lastCheck) return nil diff --git a/hscontrol/auth.go b/hscontrol/auth.go index f62fd2f97b8..1f47593374b 100644 --- a/hscontrol/auth.go +++ b/hscontrol/auth.go @@ -401,7 +401,7 @@ func (h *Headscale) handleAuthKey( } } - err = h.db.DB.Transaction(func(tx *gorm.DB) error { + h.db.Write(func(tx *gorm.DB) error { return db.UsePreAuthKey(tx, pak) }) if err != nil { @@ -633,7 +633,7 @@ func (h *Headscale) handleNodeKeyRefresh( Str("node", node.Hostname). Msg("We have the OldNodeKey in the database. This is a key refresh") - err := h.db.DB.Transaction(func(tx *gorm.DB) error { + err := h.db.Write(func(tx *gorm.DB) error { return db.NodeSetNodeKey(tx, &node, registerRequest.NodeKey) }) if err != nil { diff --git a/hscontrol/db/preauth_keys_test.go b/hscontrol/db/preauth_keys_test.go index 2cd59c40c69..fa9681ac8af 100644 --- a/hscontrol/db/preauth_keys_test.go +++ b/hscontrol/db/preauth_keys_test.go @@ -147,7 +147,7 @@ func (*Suite) TestEphemeralKeyReusable(c *check.C) { _, err = db.getNode("test7", "testest") c.Assert(err, check.IsNil) - db.DB.Transaction(func(tx *gorm.DB) error { + db.Write(func(tx *gorm.DB) error { DeleteExpiredEphemeralNodes(tx, time.Second*20) return nil }) @@ -181,7 +181,7 @@ func (*Suite) TestEphemeralKeyNotReusable(c *check.C) { _, err = db.getNode("test7", "testest") c.Assert(err, check.IsNil) - db.DB.Transaction(func(tx *gorm.DB) error { + db.Write(func(tx *gorm.DB) error { DeleteExpiredEphemeralNodes(tx, time.Second*20) return nil }) diff --git a/hscontrol/grpcv1.go b/hscontrol/grpcv1.go index d81d48e91f9..4310a617a84 100644 --- a/hscontrol/grpcv1.go +++ b/hscontrol/grpcv1.go @@ -145,7 +145,7 @@ func (api headscaleV1APIServer) ExpirePreAuthKey( ctx context.Context, request *v1.ExpirePreAuthKeyRequest, ) (*v1.ExpirePreAuthKeyResponse, error) { - err := api.h.db.DB.Transaction(func(tx *gorm.DB) error { + err := api.h.db.Write(func(tx *gorm.DB) error { preAuthKey, err := db.GetPreAuthKey(tx, request.GetUser(), request.Key) if err != nil { return err diff --git a/hscontrol/oidc.go b/hscontrol/oidc.go index 0680ce2f8af..b728a6d0091 100644 --- a/hscontrol/oidc.go +++ b/hscontrol/oidc.go @@ -602,7 +602,7 @@ func (h *Headscale) registerNodeForOIDCCallback( return err } - if err := h.db.DB.Transaction(func(tx *gorm.DB) error { + if err := h.db.Write(func(tx *gorm.DB) error { if _, err := db.RegisterNodeFromAuthCallback( // TODO(kradalby): find a better way to use the cache across modules tx, diff --git a/hscontrol/poll.go b/hscontrol/poll.go index 82d91cbad15..4a1d13ad667 100644 --- a/hscontrol/poll.go +++ b/hscontrol/poll.go @@ -467,7 +467,7 @@ func (h *Headscale) updateNodeOnlineStatus(online bool, node *types.Node) { node.LastSeen = &now change.LastSeen = &now - err := h.db.DB.Transaction(func(tx *gorm.DB) error { + err := h.db.Write(func(tx *gorm.DB) error { return db.SetLastSeen(tx, node.ID, *node.LastSeen) }) if err != nil {