Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: Improve kernel stability by eliminating some data races https://github.com/siyuan-note/siyuan/issues/9842

Daniel26e3f6807b94
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index e34c82de02..0b2601d3fb 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -676,7 +676,7 @@ func GetOnlineKernels() (ret []*OnlineKernel) {
return
}
-var closedSyncWebSocket = false
+var closedSyncWebSocket = atomic.Bool{}
func closeSyncWebSocket() {
defer logging.Recover()
@@ -687,7 +687,7 @@ func closeSyncWebSocket() {
if nil != webSocketConn {
webSocketConn.Close()
webSocketConn = nil
- closedSyncWebSocket = true
+ closedSyncWebSocket.Store(true)
}
logging.LogInfof("sync websocket closed")
@@ -732,7 +732,7 @@ func connectSyncWebSocket() {
result := gulu.Ret.NewResult()
if readErr := webSocketConn.ReadJSON(&result); nil != readErr {
time.Sleep(1 * time.Second)
- if closedSyncWebSocket {
+ if closedSyncWebSocket.Load() {
return
}
@@ -803,7 +803,7 @@ func dialSyncWebSocket() (c *websocket.Conn, err error) {
}
c, _, err = websocket.DefaultDialer.Dial(endpoint, header)
if nil == err {
- closedSyncWebSocket = false
+ closedSyncWebSocket.Store(false)
}
return
}
diff --git a/kernel/util/working.go b/kernel/util/working.go
index 54e3e471c0..28048705af 100644
--- a/kernel/util/working.go
+++ b/kernel/util/working.go
@@ -174,8 +174,12 @@ func IsBooted() bool {
return 100 <= bootProgress.Load()
}
-func GetBootProgressDetails() (int32, string) {
- return bootProgress.Load(), bootDetails
+func GetBootProgressDetails() (progress int32, details string) {
+ progress = bootProgress.Load()
+ bootDetailsLock.Lock()
+ details = bootDetails
+ bootDetailsLock.Unlock()
+ return
}
func GetBootProgress() int32 {