Skip to content

Commit ce41dcd

Browse files
YusukeShimizuclaude
andcommitted
fix: Move CLN sync wait to background to prevent plugin init timeout
- Replace blocking waitForClnSynced with async background monitoring - Check sync status once during init, continue immediately if not synced - Start background goroutine to monitor sync completion - Prevents CLN plugin manager from killing plugin due to 60s init timeout - Resolves CI test failures where CLN sync takes longer than plugin timeout 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 39718dc commit ce41dcd

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

cmd/peerswap-plugin/main.go

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,27 @@ func run(ctx context.Context, lightningPlugin *clightning.ClightningClient) erro
155155
return fmt.Errorf("Core-Lightning version %s is incompatible", nodeInfo.Version)
156156
}
157157

158-
// We want to make sure that cln is synced and ready to use before we
159-
// continue to start services.
160-
log.Infof("Waiting for cln to be synced...")
161-
err = waitForClnSynced(lightningPlugin.GetLightningRpc(), 10*time.Second)
158+
// Check CLN sync status without blocking init phase
159+
log.Infof("Checking cln sync status...")
160+
info, err := lightningPlugin.GetLightningRpc().GetInfo()
162161
if err != nil {
163162
return err
164163
}
165-
log.Infof("Cln synced, continue...")
164+
165+
if info.IsBitcoindSync() && info.IsLightningdSync() {
166+
log.Infof("Cln already synced, continue...")
167+
} else {
168+
log.Infof("Cln not fully synced yet, starting sync monitor in background...")
169+
// Start background sync monitoring after init completes
170+
go func() {
171+
err := waitForClnSynced(lightningPlugin.GetLightningRpc(), 10*time.Second)
172+
if err != nil {
173+
log.Infof("Background sync wait failed: %s", err.Error())
174+
} else {
175+
log.Infof("Cln sync completed in background")
176+
}
177+
}()
178+
}
166179

167180
// liquid
168181
var liquidOnChainService *onchain.LiquidOnChain
@@ -519,14 +532,11 @@ func setPanicLogger() (func() error, error) {
519532
}
520533

521534
// waitForClnSynced waits until cln is synced to the blockchain and the network.
522-
// This call is blocking with a maximum timeout.
535+
// This call is blocking and should be used in background goroutines only.
523536
func waitForClnSynced(cln *glightning.Lightning, tick time.Duration) error {
524537
ticker := time.NewTicker(tick)
525538
defer ticker.Stop()
526539

527-
// Add timeout to prevent indefinite blocking during plugin initialization
528-
timeout := time.After(45 * time.Second)
529-
530540
for {
531541
select {
532542
case <-ticker.C:
@@ -537,10 +547,6 @@ func waitForClnSynced(cln *glightning.Lightning, tick time.Duration) error {
537547
if info.IsBitcoindSync() && info.IsLightningdSync() {
538548
return nil
539549
}
540-
case <-timeout:
541-
// If not synced within timeout, log warning but don't fail
542-
log.Infof("CLN sync timeout reached, continuing with plugin initialization")
543-
return nil
544550
}
545551
}
546552
}

0 commit comments

Comments
 (0)