Segments randomly missing from the cache #2885
Replies: 5 comments 19 replies
-
I've looked through the code but couldn't find the source of the problem. |
Beta Was this translation helpful? Give feedback.
-
@JanDeDobbeleer I tested it in PowerShell by continuously pressing Ctrl + L to redraw the prompt, and I noticed that an expected The custom theme I use for tests:palette:
darkOliveGreen: "#556b2f"
chocolate: "#d2691e"
teal: "#008080"
dodgerBlue: "#1e90ff"
blocks:
- alignment: left
segments:
- foreground: white
style: plain
template: ╭─
type: text
- background: blue
foreground: white
leading_diamond:
style: diamond
template: " {{if .WSL}}[<lightGreen>WSL</>]{{end}}{{.Icon}} <lightYellow>{{.Shell}}</> "
type: os
- background: white
foreground: black
powerline_symbol:
style: powerline
template: " {{if .SSHSession}} {{end}}{{if .Root}} {{else}} {{end}}<p:dodgerBlue><b>{{.UserName}}</b></><green>@</> <p:chocolate><b>{{.HostName}}</b></> "
type: session
- background: p:teal
foreground: white
style: powerline
powerline_symbol:
template: "{{.Segments.Exit.Meaning}} {{.CurrentDate | date .Format}} "
type: time
- background_templates:
- "{{if ne .Code 0}}red{{else}}green{{end}}"
foreground: white
properties:
always_enabled: true
powerline_symbol:
style: powerline
template: " {{if ne .Code 0}} {{.Code}}{{else}} ✔{{end}} "
type: exit
- background: p:darkOliveGreen
foreground: white
properties:
always_enabled: true
powerline_symbol:
style: powerline
template: "{{if ne .Ms 0}} {{.FormattedMs}} {{end}}"
type: executiontime
- background: magenta
foreground: white
properties:
style: folder
mapped_locations_enabled: false
mapped_locations:
"~": "~"
style: diamond
template: " {{if gt .StackCount 0}}[<lightGreen><b>{{.StackCount}}</b></>] {{end}} {{.Parent}}<lightGreen>{{.Path}}</> "
trailing_diamond:
type: path
type: prompt
- alignment: left
newline: true
segments:
- style: plain
template: "╰─<lightGreen></> "
type: text
type: prompt
console_title_template: "{{if .Root}}*{{end}}{{.Shell}} | {{.UserName}}@{{.HostName}} | {{.PWD}}"
secondary_prompt:
foreground: darkGray
template: "»»» "
valid_line:
foreground: lightGreen
template: " "
error_line:
foreground: lightRed
template: " "
transient_prompt:
template: "<lightGreen> </> "
version: 2 |
Beta Was this translation helpful? Give feedback.
-
After some debugging and tests, I finally found the culprit for this. 👻 It's not exactly a concurrent cache-writing issue, but associated with concurrency (Goroutines) indeed. Let's consider this call hierarchy:
The keypoint is that In (1), one Goroutine is created for each segment's Make a change in block.go like the following (i.e., to remove the concurrency) is a feasible solution: (validated) --- a/src/engine/block.go
+++ b/src/engine/block.go
@@ -109,10 +109,8 @@ func (b *Block) setEnabledSegments() {
wg.Add(len(b.Segments))
defer wg.Wait()
for _, segment := range b.Segments {
- go func(s *Segment) {
- defer wg.Done()
- s.SetEnabled(b.env)
- }(segment)
+ segment.SetEnabled(b.env)
+ wg.Done()
}
} Perhaps there is a better option. @JanDeDobbeleer Any ideas? |
Beta Was this translation helpful? Give feedback.
-
@JanDeDobbeleer I noticed that this bug has reappeared since the commit 4e19379 in which you tried to fix another bug. |
Beta Was this translation helpful? Give feedback.
-
@JanDeDobbeleer The problem reappears in v24. Still broken in v24.0.11. :( |
Beta Was this translation helpful? Give feedback.
-
For cross-segment template references, OMP caches segment data via
(*environment.TemplateCache).AddSegmentData
. However, this does not seem to work well. I tested it (e.g.,{{.Segments.Exit.Meaning}}
) on Windows/Linux and I found that every time OMP updates the cache file, some segments are randomly missing from the cachedSegments
map, which makes a cross-segment template not always available.Beta Was this translation helpful? Give feedback.
All reactions