Skip to content

Commit df87ae8

Browse files
committed
subservers: sort sub-servers deterministically during integrated startup
- Ensure critical integrated sub-servers initialize first. - Introduce alphabetical sorting for consistent order across startup runs.
1 parent 855b1f7 commit df87ae8

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

subservers/manager.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io/ioutil"
7+
"sort"
78
"sync"
89
"time"
910

@@ -118,7 +119,29 @@ func (s *Manager) StartIntegratedServers(lndClient lnrpc.LightningClient,
118119
s.mu.Lock()
119120
defer s.mu.Unlock()
120121

122+
// Sort for deterministic startup: critical integrated sub-servers
123+
// first, then alphabetical to keep the order stable across runs.
124+
servers := make([]*subServerWrapper, 0, len(s.servers))
121125
for _, ss := range s.servers {
126+
servers = append(servers, ss)
127+
}
128+
129+
sort.Slice(servers, func(i, j int) bool {
130+
iCritical := criticalIntegratedSubServers.Contains(
131+
servers[i].Name(),
132+
)
133+
jCritical := criticalIntegratedSubServers.Contains(
134+
servers[j].Name(),
135+
)
136+
137+
if iCritical != jCritical {
138+
return iCritical
139+
}
140+
141+
return servers[i].Name() < servers[j].Name()
142+
})
143+
144+
for _, ss := range servers {
122145
if ss.Remote() {
123146
continue
124147
}

0 commit comments

Comments
 (0)