Skip to content

Commit 930adb3

Browse files
committed
Fix policy override, Bootstrap deadlock, duplicate history samples
- registry.Client.SetNetworkPolicy: build message from copy of policy map so caller keys cannot override type/network_id/admin_token fields - daemon.ManagedEngine.Bootstrap: release me.mu before calling persist (which takes RLock on same mutex) to avoid deadlock - registry.Server.recordSample: bucket samples by hour/day timestamp so restarts within the same bucket overwrite rather than duplicate entries
1 parent 36563b7 commit 930adb3

4 files changed

Lines changed: 779 additions & 13 deletions

File tree

pkg/daemon/managed.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ func (me *ManagedEngine) Bootstrap() error {
116116
}
117117

118118
me.mu.Lock()
119-
defer me.mu.Unlock()
120-
121119
now := time.Now()
122120
for _, id := range candidates[:limit] {
123121
if _, exists := me.peers[id]; !exists {
@@ -127,9 +125,11 @@ func (me *ManagedEngine) Bootstrap() error {
127125
}
128126
}
129127
}
128+
peerCount := len(me.peers)
129+
me.mu.Unlock()
130130

131131
me.persist()
132-
slog.Info("managed: bootstrapped", "network_id", me.netID, "peers", len(me.peers), "available", len(candidates))
132+
slog.Info("managed: bootstrapped", "network_id", me.netID, "peers", peerCount, "available", len(candidates))
133133
return nil
134134
}
135135

pkg/registry/client.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,12 @@ func (c *Client) GetMemberRole(networkID uint16, targetNodeID uint32) (map[strin
700700

701701
// SetNetworkPolicy sets or updates a network's policy. Requires owner/admin role or admin token.
702702
func (c *Client) SetNetworkPolicy(networkID uint16, policy map[string]interface{}, adminToken string) (map[string]interface{}, error) {
703-
msg := map[string]interface{}{
704-
"type": "set_network_policy",
705-
"network_id": networkID,
706-
}
703+
msg := map[string]interface{}{}
707704
for k, v := range policy {
708705
msg[k] = v
709706
}
707+
msg["type"] = "set_network_policy"
708+
msg["network_id"] = networkID
710709
if adminToken != "" {
711710
msg["admin_token"] = adminToken
712711
}

0 commit comments

Comments
 (0)