"fatal error: sync: Unlock of unlocked RWMutex" while adding Dropdown menu to form #35

Closed
opened 2020-09-27 23:14:45 +00:00 by damnwidget · 2 comments
damnwidget commented 2020-09-27 23:14:45 +00:00 (Migrated from gitlab.com)

Hi guys,

I am currently writing a terminal based installer for our Linux distribution (Artix Linux) based in cview (actually moved from tview pretty recently) and I am having a very strange panic about a RWMutex trying to be unlocked while it is not locked, the funny part is that there is not a single RWMutex in our custom structures and the unlock is happening when we try to make modifications to a local slice that has absolutely nothing to do with cview. I've spend considerably long time already looking for the possible cause of the issue and I could not find anything, actually while debugging the code jumps to the Unlock method on the standard library RWMutex as soon as the execution of the application reach the given point (more details below).

We are following a bit the design on the presentation let me show you the application code.

The problematic section (a *cview.Page actually) is being initialized in cmd/aim/application.go:46, that is defined in internal/ui/sections/localization.go:241 that as you can see uses the localizationHandler function defined just below that simply adds pages containing forms to a Pages primitive.

We have a bit of wrapping in there, the localizationMultiForm data structure embedds a Multiform that is just a thin wrapper around a *cview.Pages that includes a slice of pointers to values of a data structure called MultiFormChoice, the idea behind the whole multiform thing is to present different forms that asks the users to input data or make choices in drop down select boxes (like a typical GUI installation application), the multiform registers the choices the users made on each step in its choices property.

In internal/ui/sections/localization.go:86-93 we add a DropDown to one of the forms, on its selection method we call the MultiForm's SetChoice that when called will just set a string with the value of the selected choice, the problem is that when the execution reaches line 138 the code just jumps to the aforementioned Unlock method and you get a fatal error: sync: Unlock of unlocked RWMutex

I am not sure if we are doing something very wrong in here but I tried to use a global variable in the localization pacage and when I try to access it using the index operator the same problem occurs.

We also use this wrapper around cview.Form but that only adds empty boxes around the form to make it to be draw in the center of the screen.

Anyone has any idea of what could be the problem here? We will be eternally grateful to any kind soul that can lend us a hand because this problem has been driving us nuts for a while and we have no clue what can be happening here.

Thank you in advance and continue with the good work.

Hi guys, I am currently writing a terminal based installer for our Linux distribution (Artix Linux) based in cview (actually moved from tview pretty recently) and I am having a very strange panic about a RWMutex trying to be unlocked while it is not locked, the funny part is that there is not a single RWMutex in our custom structures and the unlock is happening when we try to make modifications to a local slice that has absolutely nothing to do with cview. I've spend considerably long time already looking for the possible cause of the issue and I could not find anything, actually while debugging the code jumps to the `Unlock` method on the standard library `RWMutex` as soon as the execution of the application reach the given point (more details below). We are following a bit the design on the `presentation` let me show you the application code. The problematic section (a *cview.Page actually) is being initialized in [cmd/aim/application.go:46](https://gitea.artixlinux.org/artix/aim/src/branch/master/cmd/aim/application.go#L46), that is defined in [internal/ui/sections/localization.go:241](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/sections/localization/localization.go#L241) that as you can see uses the `localizationHandler` function defined just below that simply adds pages containing forms to a Pages primitive. We have a bit of wrapping in there, the `localizationMultiForm` data structure embedds a [Multiform](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/multiform/multiform.go) that is just a thin wrapper around a *cview.Pages that includes a slice of pointers to values of a data structure called [MultiFormChoice](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/multiform/multiform.go#L45), the idea behind the whole multiform thing is to present different forms that asks the users to input data or make choices in drop down select boxes (like a typical GUI installation application), the multiform registers the choices the users made on each step in its [choices](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/multiform/multiform.go#L81) property. In [internal/ui/sections/localization.go:86-93](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/sections/localization/localization.go#L86-L93) we add a DropDown to one of the forms, on its selection method we call the `MultiForm`'s [SetChoice](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/multiform/multiform.go#L126) that when called will just set a string with the value of the selected choice, the problem is that when the execution reaches [line 138](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/multiform/multiform.go#L138) the code just jumps to the aforementioned `Unlock` method and you get a `fatal error: sync: Unlock of unlocked RWMutex` I am not sure if we are doing something very wrong in here but I tried to use a global variable in the `localization` pacage and when I try to access it using the index operator the same problem occurs. We also use [this wrapper](https://gitea.artixlinux.org/artix/aim/src/branch/master/internal/ui/widgets/form/form.go) around `cview.Form` but that only adds empty boxes around the form to make it to be draw in the center of the screen. Anyone has any idea of what could be the problem here? We will be eternally grateful to any kind soul that can lend us a hand because this problem has been driving us nuts for a while and we have no clue what can be happening here. Thank you in advance and continue with the good work.
tslocum commented 2020-09-28 16:52:35 +00:00 (Migrated from gitlab.com)

Thanks for reporting this. I ran into something similar recently and this is helpful in narrowing the cause. I believe this problem was introduced with these recent changes. I'll look into this.

Thanks for reporting this. I ran into something similar recently and this is helpful in narrowing the cause. I believe this problem was introduced with [these recent changes](https://gitlab.com/tslocum/cview/-/commit/70857602a59f26523857f98d3049fa4857fd9a47). I'll look into this.
damnwidget commented 2020-09-28 18:33:38 +00:00 (Migrated from gitlab.com)

Thank you Trevor, let me know if I can do anything to help you.

Thank you Trevor, let me know if I can do anything to help you.
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#35
There is no content yet.