panic: runtime error: index out of range [0] with length 0 in StatusManager.GetStatusString
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start in pkg/gui/status/status_manager.go, reading GetStatusString and HasStatus alongside addStatus and removeStatus to understand the mutex usage. Check the call site in pkg/gui/controllers/helpers/app_status_helper.go. Done means both read methods hold the mutex for the complete status read so concurrent removal cannot cause the reported index-out-of-range panic.
Written by the indexing model from the issue text.
Description
StatusManager.GetStatusString (and HasStatus) read self.statuses without holding the mutex, while addStatus and removeStatus both do hold it. This creates a TOCTOU race: the len == 0 check passes, another goroutine calls removeStatus between the check and the self.statuses[0] access, and the index-out-of-range panic results.
Stack trace:
panic: runtime error: index out of range [0] with length 0
goroutine 2424671 [running]:
github.com/jesseduffield/lazygit/pkg/gui/status.(*StatusManager).GetStatusString(...)
pkg/gui/status/status_manager.go:76
github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers.(*AppStatusHelper).renderAppStatus.func1(...)
pkg/gui/controllers/helpers/app_status_helper.go:106
Fix: lock the mutex for the full read in both GetStatusString and HasStatus:
func (self *StatusManager) GetStatusString(userConfig *config.UserConfig) (string, gocui.Attribute) {
self.mutex.Lock()
defer self.mutex.Unlock()
if len(self.statuses) == 0 {
return "", gocui.ColorDefault
}
// ...
}
func (self *StatusManager) HasStatus() bool {
self.mutex.Lock()
defer self.mutex.Unlock()
return len(self.statuses) > 0
}
- Dominant language
- Go
- Stars
- 82.5k
- Forks
- 3k
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 22
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jesseduffield/lazygit
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
jesseduffield/lazygit#6046 · 4 comments ·
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
jesseduffield/lazygit#5742 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
jesseduffield/lazygit#5716 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
jesseduffield/lazygit#5672 ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
jesseduffield/lazygit#5654 ·
All issues in jesseduffield/lazygit
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100