cogentcore / core

A free and open source framework for building powerful, fast, and elegant 2D and 3D apps that run on macOS, Windows, Linux, iOS, Android, and the Web with a single pure Go codebase, allowing you to Code Once, Run Everywhere.
http://cogentcore.org/core
BSD 3-Clause "New" or "Revised" License
1.32k stars 71 forks source link

fatal error: concurrent map writes #851

Closed ddkwork closed 5 months ago

ddkwork commented 5 months ago

Describe the bug

GOROOT=C:\Users\Admin\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.21.6.windows-amd64 #gosetup
GOPATH=C:\Users\Admin\go #gosetup
C:\Users\Admin\go\pkg\mod\golang.org\toolchain@v0.0.1-go1.21.6.windows-amd64\bin\go.exe build -o C:\Users\Admin\AppData\Local\JetBrains\GoLand2023.3\tmp\GoLand\___go_build_github_com_ddkwork_golibrary_widget_cmd.exe github.com/ddkwork/golibrary/widget/cmd #gosetup
C:\Users\Admin\AppData\Local\JetBrains\GoLand2023.3\tmp\GoLand\___go_build_github_com_ddkwork_golibrary_widget_cmd.exe
fatal error: concurrent map writes

goroutine 595 [running]:
cogentcore.org/core/events.(*Listeners).Add(...)
        D:/workspace/workspace/core/events/listeners.go:30
cogentcore.org/core/gi.(*WidgetBase).On(...)
        D:/workspace/workspace/core/gi/events.go:45
cogentcore.org/core/gi.(*WidgetBase).OnClose(...)
        D:/workspace/workspace/core/gi/events.go:139
cogentcore.org/core/gi.(*TextField).OnAdd(0xc0015baa80)
        D:/workspace/workspace/core/gi/textfield.go:154 +0x1a5
cogentcore.org/core/ki.SetParent({0x7ff65cc368f0, 0xc0015baa80}, {0x7ff65cc343c0?, 0xc0014aa400})
        D:/workspace/workspace/core/ki/admin.go:61 +0x167
cogentcore.org/core/ki.(*Slice).Config(0xc0014aa430, {0x7ff65cc343c0, 0xc0014aa400?}, {0xc0057a5200, 0x2a, 0x0?})
        D:/workspace/workspace/core/ki/slice.go:340 +0x659
cogentcore.org/core/ki.(*Node).ConfigChildren(0xc0014aa400, {0xc0057a5200, 0x2a, 0x40})
        D:/workspace/workspace/core/ki/node.go:571 +0x55
cogentcore.org/core/giv.(*StructView).ConfigStructGrid(0xc0014a9b00)
        D:/workspace/workspace/core/giv/structview.go:278 +0x216
cogentcore.org/core/giv.(*StructView).ConfigWidget(0xc0014a9b00)
        D:/workspace/workspace/core/giv/structview.go:130 +0xff
cogentcore.org/core/gi.(*WidgetBase).Config(0xc0014a9b00)
        D:/workspace/workspace/core/gi/render.go:268 +0x5b
cogentcore.org/core/gi.(*WidgetBase).ConfigTree.func1({0x19af236ef18?, 0xc0014a9b00?}, 0x7ff65cc1cee8?)
        D:/workspace/workspace/core/gi/render.go:306 +0x24
cogentcore.org/core/gi.(*WidgetBase).ConfigTree.(*WidgetBase).WidgetWalkPre.func2({0x7ff65cc389c0?, 0xc0014a9b00?})
        D:/workspace/workspace/core/gi/widget.go:538 +0xab
cogentcore.org/core/ki.(*Node).WalkPre(0xc000397800, 0xc008e7c740)
        D:/workspace/workspace/core/ki/node.go:878 +0x1ad
cogentcore.org/core/gi.(*WidgetBase).WidgetWalkPre(...)
        D:/workspace/workspace/core/gi/widget.go:533
cogentcore.org/core/gi.(*WidgetBase).ConfigTree(0xc000397800)
        D:/workspace/workspace/core/gi/render.go:305 +0xe7
cogentcore.org/core/gi.(*Scene).ConfigSceneWidgets(0xc000397800)
        D:/workspace/workspace/core/gi/render.go:495 +0xb3
cogentcore.org/core/gi.(*Scene).DoRebuild(0xc000397810?)
        D:/workspace/workspace/core/gi/render.go:513 +0x18
cogentcore.org/core/gi.(*Scene).DoUpdate(0xc000397800)
        D:/workspace/workspace/core/gi/render.go:447 +0x606
cogentcore.org/core/gi.(*Stage).DoUpdate(0xc007100000?)
        D:/workspace/workspace/core/gi/stage.go:330 +0x57
cogentcore.org/core/gi.(*StageMgr).UpdateAll(0xc0019b0f38)
        D:/workspace/workspace/core/gi/stagemgr.go:238 +0xcb
cogentcore.org/core/gi.(*RenderWin).RenderWindow(0xc0019b0f00)
        D:/workspace/workspace/core/gi/renderwin.go:978 +0xd2
cogentcore.org/core/gi.(*RenderWin).HandleWindowEvents(0xc0019b0f00, {0x7ff65cc2e390, 0xc009780620})
        D:/workspace/workspace/core/gi/renderwin.go:637 +0x533
cogentcore.org/core/gi.(*RenderWin).HandleEvent(0xc0019b0f00, {0x7ff65cc2e390, 0xc009780620})
        D:/workspace/workspace/core/gi/renderwin.go:622 +0xe5
cogentcore.org/core/gi.(*RenderWin).EventLoop(0xc0019b0f00)
        D:/workspace/workspace/core/gi/renderwin.go:589 +0x125
created by cogentcore.org/core/gi.(*RenderWin).GoStartEventLoop in goroutine 14
        D:/workspace/workspace/core/gi/renderwin.go:543 +0xa5

goroutine 1 [syscall, locked to thread]:
github.com/go-gl/glfw/v3.3/glfw._Cfunc_glfwWaitEvents()
        _cgo_gotypes.go:2489 +0x49
github.com/go-gl/glfw/v3.3/glfw.WaitEvents()
        C:/Users/Admin/go/pkg/mod/github.com/go-gl/glfw/v3.3/glfw@v0.0.0-20240108052320-294b0144ba39/window.go:949 +0x13
cogentcore.org/core/goosi/driver/desktop.(*App).MainLoop(0x7ff65d3e7880)
        D:/workspace/workspace/core/goosi/driver/desktop/app.go:74 +0x125
cogentcore.org/core/gi.Wait()
        D:/workspace/workspace/core/gi/renderwin.go:41 +0x4b
cogentcore.org/core/gi.(*Stage).Wait(...)
        D:/workspace/workspace/core/gi/stage.go:316
github.com/ddkwork/golibrary/widget.NewWindowRunAndWait(0xc0003a6a80?, 0x7ff65cb4b548)
        D:/workspace/workspace/golibrary/widget/Splits.go:89 +0x9e
github.com/ddkwork/golibrary/widget.TreeTable()
        D:/workspace/workspace/golibrary/widget/treeTable.go:77 +0x8d3
main.main()
        D:/workspace/workspace/golibrary/widget/cmd/main.go:6 +0xf

goroutine 14 [runnable]:
cogentcore.org/core/ki.(*Slice).Config(0xc00843c030, {0x7ff65cc36260, 0xc00843c000?}, {0xc008b625d0, 0x2, 0x1?})
        D:/workspace/workspace/core/ki/slice.go:323 +0x1b1
cogentcore.org/core/ki.(*Node).ConfigChildren(0xc00843c000, {0xc008b625d0, 0x2, 0x2})
        D:/workspace/workspace/core/ki/node.go:571 +0x55
cogentcore.org/core/gi.(*WidgetBase).ConfigParts(0xc005d7fc98?, {0xc008b625d0, 0x2, 0x2}, {0xc001f1f3d8, 0x1, 0x0?})
        D:/workspace/workspace/core/gi/render.go:287 +0x50
cogentcore.org/core/gi.(*Button).ConfigWidget(0xc008427600)
        D:/workspace/workspace/core/gi/button.go:417 +0x83a
cogentcore.org/core/gi.(*Button).SetTextUpdate(0xc008427600, {0xc0044dbdc7, 0x4})
        D:/workspace/workspace/core/gi/button.go:265 +0x51
cogentcore.org/core/giv.(*StructValue).UpdateWidget(0xc006fe6a80)
        D:/workspace/workspace/core/giv/values.go:374 +0x16c
cogentcore.org/core/giv.(*TableView).UpdateWidgets(0xc0003a6a80)
        D:/workspace/workspace/core/giv/tableview.go:618 +0xbf4
cogentcore.org/core/giv.(*TableView).ConfigTableView(0xc0003a6a80)
        D:/workspace/workspace/core/giv/tableview.go:305 +0x94
cogentcore.org/core/giv.(*TableView).ConfigWidget(0xc0003a6a80?)
        D:/workspace/workspace/core/giv/tableview.go:300 +0x13
cogentcore.org/core/gi.(*WidgetBase).Config(0xc0003a6a80)
        D:/workspace/workspace/core/gi/render.go:268 +0x5b
cogentcore.org/core/gi.(*WidgetBase).ConfigTree.func1({0x7ff65cc484c0?, 0xc0003a6a80?}, 0x7ff65cc1cee8?)
        D:/workspace/workspace/core/gi/render.go:306 +0x24
cogentcore.org/core/gi.(*WidgetBase).ConfigTree.(*WidgetBase).WidgetWalkPre.func2({0x7ff65cc34a50?, 0xc0003a6a80?})
        D:/workspace/workspace/core/gi/widget.go:538 +0xab
cogentcore.org/core/ki.(*Node).WalkPre(0xc0002f0c00, 0xc004ee5ea0)
        D:/workspace/workspace/core/ki/node.go:878 +0x1ad
cogentcore.org/core/gi.(*WidgetBase).WidgetWalkPre(...)
        D:/workspace/workspace/core/gi/widget.go:533
cogentcore.org/core/gi.(*WidgetBase).ConfigTree(0xc0002f0c00)
        D:/workspace/workspace/core/gi/render.go:305 +0xe7
cogentcore.org/core/gi.(*Scene).ConfigSceneWidgets(0xc0002f0c00)
        D:/workspace/workspace/core/gi/render.go:495 +0xb3
cogentcore.org/core/gi.(*Scene).DoRebuild(0xc0002f0c10?)
        D:/workspace/workspace/core/gi/render.go:513 +0x18
cogentcore.org/core/gi.(*Scene).DoUpdate(0xc0002f0c00)
        D:/workspace/workspace/core/gi/render.go:447 +0x606
cogentcore.org/core/gi.(*Stage).DoUpdate(0xc00031c900?)
        D:/workspace/workspace/core/gi/stage.go:330 +0x57
cogentcore.org/core/gi.(*StageMgr).UpdateAll(0xc000d2e218)
        D:/workspace/workspace/core/gi/stagemgr.go:238 +0xcb
cogentcore.org/core/gi.(*RenderWin).RenderWindow(0xc000d2e1e0)
        D:/workspace/workspace/core/gi/renderwin.go:978 +0xd2
cogentcore.org/core/gi.(*RenderWin).HandleWindowEvents(0xc000d2e1e0, {0x7ff65cc2e390, 0xc00970c8c0})
        D:/workspace/workspace/core/gi/renderwin.go:637 +0x533
cogentcore.org/core/gi.(*RenderWin).HandleEvent(0xc000d2e1e0, {0x7ff65cc2e390, 0xc00970c8c0})
        D:/workspace/workspace/core/gi/renderwin.go:622 +0xe5
cogentcore.org/core/gi.(*RenderWin).EventLoop(0xc000d2e1e0)
        D:/workspace/workspace/core/gi/renderwin.go:589 +0x125
created by cogentcore.org/core/gi.(*RenderWin).GoStartEventLoop in goroutine 1
        D:/workspace/workspace/core/gi/renderwin.go:543 +0xa5

goroutine 13 [select]:
cogentcore.org/core/goosi/driver/base.(*Window[...]).WinLoop(0x7ff65cc2aec0)
        D:/workspace/workspace/core/goosi/driver/base/window.go:93 +0x133
created by cogentcore.org/core/goosi/driver/desktop.(*App).NewWindow in goroutine 1
        D:/workspace/workspace/core/goosi/driver/desktop/app.go:172 +0xa73

goroutine 15 [semacquire, 6 minutes]:
sync.runtime_Semacquire(0x0?)
        C:/Users/Admin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.6.windows-amd64/src/runtime/sema.go:62 +0x25
sync.(*WaitGroup).Wait(0x0?)
        C:/Users/Admin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.6.windows-amd64/src/sync/waitgroup.go:116 +0x48
cogentcore.org/core/gi.Wait.func2()
        D:/workspace/workspace/core/gi/renderwin.go:38 +0x37
created by cogentcore.org/core/gi.Wait in goroutine 1
        D:/workspace/workspace/core/gi/renderwin.go:36 +0x37

goroutine 594 [select]:
cogentcore.org/core/goosi/driver/base.(*Window[...]).WinLoop(0x7ff65cc2aec0)
        D:/workspace/workspace/core/goosi/driver/base/window.go:93 +0x133
created by cogentcore.org/core/goosi/driver/desktop.(*App).NewWindow in goroutine 14
        D:/workspace/workspace/core/goosi/driver/desktop/app.go:172 +0xa73

Process finished with the exit code 2

How to reproduce

Click on global settings, edit the color, panic occurs, so D:workspaceworkspacecoreeventslisteners.go type Listeners map[Types][]func(ev Event) should use concurrent map, github.com/orcaman/concurrent-map/v2.

Example code

No response

Relevant output

No response

Platform

Windows

kkoreilly commented 5 months ago

I will look into this.

ddkwork commented 5 months ago

I will look into this.

I'm not sure if you'd agree to bring in a third-party library, in that case I'll create a PR to fix the bug, and on the other hand, can you reproduce the bug over there?

kkoreilly commented 5 months ago

We need to use UpdateAsync in UpdateAll for other windows to fix this. We will implement this soon.

kkoreilly commented 5 months ago

You do not need to do a PR.

ddkwork commented 5 months ago

You do not need to do a PR.

okay

rcoreilly commented 5 months ago

Actually, we are not driving the update in UpdateAll -- just setting the full rebuild flag, so it should be fully safe, and I've never seen a conflict like this before -- must be something else. Looks like Kai cannot replicate either. Would be good to know more about the context of this if it is fully reproducible?

ddkwork commented 5 months ago

I don't know why, but it's back to normal today