Random crashes when printing out to TextView #4

Closed
opened 2 years ago by michal.kluczek · 5 comments
michal.kluczek commented 2 years ago (Migrated from gitlab.com)
Owner

I quite often get panics when printing many lines to TextView. It might have something to do with concurrency but I'm not sure about that.

Here's an example panic. The only thing that changes between crashes is the index

panic: runtime error: index out of range [143] with length 0 [recovered]
	panic: runtime error: index out of range [143] with length 0

goroutine 1 [running]:
gitlab.com/tslocum/cview.(*Application).Run.func1(0xc000152000)
	/Users/retard/go/src/gitlab.com/tslocum/cview/application.go:225 +0x82
panic(0x119aea0, 0xc000736400)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
gitlab.com/tslocum/cview.(*TextView).Draw(0xc00009b110, 0x11e0540, 0xc000154000)
	/Users/retard/go/src/gitlab.com/tslocum/cview/textview.go:847 +0xa74
gitlab.com/tslocum/cview.(*Flex).Draw(0xc0000989c0, 0x11e0540, 0xc000154000)
	/Users/retard/go/src/gitlab.com/tslocum/cview/flex.go:173 +0x28b
gitlab.com/tslocum/cview.(*Application).draw(0xc000152000, 0x0)
	/Users/retard/go/src/gitlab.com/tslocum/cview/application.go:597 +0x105
gitlab.com/tslocum/cview.(*Application).Draw.func1()
	/Users/retard/go/src/gitlab.com/tslocum/cview/application.go:550 +0x2a
gitlab.com/tslocum/cview.(*Application).Run(0xc000152000, 0x0, 0x0)
	/Users/retard/go/src/gitlab.com/tslocum/cview/application.go:442 +0xe4f
main.main()
	/Users/retard/GIT/tempest/poc.go:72 +0x449
exit status 2

Here's demo of this issue
https://asciinema.org/a/6TZMAMJUSkHsydOm86tyXCXB5

And a proof of concept's code
https://paste.ring0.cc/uxajezuhig

PS
Thanks Trevor for taking over the initiative for tview. I really like the speed improvements together with progress and scrollbars :)

I quite often get panics when printing many lines to TextView. It might have something to do with concurrency but I'm not sure about that. Here's an example panic. The only thing that changes between crashes is the index panic: runtime error: index out of range [143] with length 0 [recovered] panic: runtime error: index out of range [143] with length 0 goroutine 1 [running]: gitlab.com/tslocum/cview.(*Application).Run.func1(0xc000152000) /Users/retard/go/src/gitlab.com/tslocum/cview/application.go:225 +0x82 panic(0x119aea0, 0xc000736400) /usr/local/go/src/runtime/panic.go:679 +0x1b2 gitlab.com/tslocum/cview.(*TextView).Draw(0xc00009b110, 0x11e0540, 0xc000154000) /Users/retard/go/src/gitlab.com/tslocum/cview/textview.go:847 +0xa74 gitlab.com/tslocum/cview.(*Flex).Draw(0xc0000989c0, 0x11e0540, 0xc000154000) /Users/retard/go/src/gitlab.com/tslocum/cview/flex.go:173 +0x28b gitlab.com/tslocum/cview.(*Application).draw(0xc000152000, 0x0) /Users/retard/go/src/gitlab.com/tslocum/cview/application.go:597 +0x105 gitlab.com/tslocum/cview.(*Application).Draw.func1() /Users/retard/go/src/gitlab.com/tslocum/cview/application.go:550 +0x2a gitlab.com/tslocum/cview.(*Application).Run(0xc000152000, 0x0, 0x0) /Users/retard/go/src/gitlab.com/tslocum/cview/application.go:442 +0xe4f main.main() /Users/retard/GIT/tempest/poc.go:72 +0x449 exit status 2 Here's demo of this issue https://asciinema.org/a/6TZMAMJUSkHsydOm86tyXCXB5 And a proof of concept's code https://paste.ring0.cc/uxajezuhig PS Thanks Trevor for taking over the initiative for tview. I really like the speed improvements together with progress and scrollbars :)
tslocum commented 2 years ago (Migrated from gitlab.com)
Owner

Thanks for reporting this and for the shout-out. I will look into this further when I have time but perhaps this is caused by TexView.Write being goroutine-safe, while TextView.SetText isn't (because it calls TextView.Clear without locking). Wrapping the SetText call with Application.QueueUpdate might resolve this.

Thanks for reporting this and for the shout-out. I will look into this further when I have time but perhaps this is caused by TexView.Write being goroutine-safe, while TextView.SetText isn't (because it calls TextView.Clear without locking). Wrapping the SetText call with Application.QueueUpdate might resolve this.
michal.kluczek commented 2 years ago (Migrated from gitlab.com)
Owner

I see. I'll try that one too. For now I used such workaround

func Log(line string) {
	cview.ANSIWriter(output).Write([]byte(line + "\n\n"))
}
I see. I'll try that one too. For now I used such workaround func Log(line string) { cview.ANSIWriter(output).Write([]byte(line + "\n\n")) }
tslocum commented 2 years ago (Migrated from gitlab.com)
Owner

Will you also try reverting to your original code and switching from civew@master to cview@thread with:

go get gitlab.com/tslocum/cview@thread

And try running the program, and let me know if the crash is resolved? You can then revert back with:

go get gitlab.com/tslocum/cview@master

Will you also try reverting to your original code and switching from civew@master to cview@thread with: `go get gitlab.com/tslocum/cview@thread` And try running the program, and let me know if the crash is resolved? You can then revert back with: `go get gitlab.com/tslocum/cview@master`
tslocum commented 2 years ago (Migrated from gitlab.com)
Owner

I've merged the multithreading changes, please let me know if updating to the latest master resolves your issue.

I've merged the multithreading changes, please let me know if updating to the latest master resolves your issue.
tslocum commented 2 years ago (Migrated from gitlab.com)
Owner

closed

closed
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

This issue currently doesn't have any dependencies.

Loading…
There is no content yet.