Random crashes when printing out to TextView #4

Closed
opened 2020-03-22 14:28:02 +00:00 by michal.kluczek · 5 comments
michal.kluczek commented 2020-03-22 14:28:02 +00:00 (Migrated from gitlab.com)

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 2020-03-23 03:50:56 +00:00 (Migrated from gitlab.com)

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 2020-03-23 11:22:54 +00:00 (Migrated from gitlab.com)

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 2020-03-23 13:52:31 +00:00 (Migrated from gitlab.com)

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 2020-03-25 14:51:44 +00:00 (Migrated from gitlab.com)

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 2020-04-22 03:03:29 +00:00 (Migrated from gitlab.com)

closed

closed
Sign in to join this conversation.
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: tslocum/cview#4
There is no content yet.