loopd: shutdown hangs when lnd goes away

未关闭
#1,309 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
半天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
go

调研方向

Start in loopd/daemon.go: the internalErrChan buffer size where it is created, the swap client send near line 854, the static address loop-in manager send near line 1048, and Daemon.stop near line 1164. Reproduce by stopping and restarting lnd under a running loopd and watching for the hang after 'Runtime error in daemon, shutting down'. Done when shutdown completes, the macaroon db is released, and a new loopd can start.

由索引模型根据 Issue 内容生成。

描述

When lnd stops or restarts under a running loopd, the daemon starts to shut down and then hangs. The process stays alive, the RPC port is closed, and the macaroon database stays locked, so a new loopd fails with "unable to open macaroon db: timeout".

Cause

internalErrChan has room for four errors (make(chan error, 4) in loopd/daemon.go) and is read once. After that read the daemon calls stop(), which waits for the wait group. When lnd goes away, more goroutines report an error than the channel can hold. The rest block on the send, inside goroutines the wait group is waiting for.

The comment at the swap client's send says "We don't have to worry about blocking as the internal error channel is sufficiently buffered", which no longer holds with the number of managers that now send to it.

Goroutine dump from a hung daemon on master (b41a3a32):

goroutine 114 [chan send]:            loopd/daemon.go:854   (swap client)
goroutine 218 [chan send]:            loopd/daemon.go:1048  (static address loop-in manager)
goroutine 364 [sync.WaitGroup.Wait]:  loopd/daemon.go:1164  (*Daemon).stop
Steps
  1. Run loopd against lnd on regtest, with experimental features on.
  2. Restart lnd.
  3. loopd logs "Runtime error in daemon, shutting down" and never logs "Daemon exited".

Reproduced three times in three tries.

Possible fix

Send to internalErrChan without blocking (a select with d.quit, or a default case), or keep draining the channel while stop() runs.

主要语言
Go
星标
593
派生
139
平均合并
2 天 8 小时
30 天内合并 PR
21

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

lightninglabs/loop 的其他 Issue

查看 lightninglabs/loop 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。