mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🐛 桌面端内核在授权页自动退出 https://github.com/siyuan-note/insider/issues/1099
This commit is contained in:
parent
cca4eeb207
commit
2be5545dbf
3 changed files with 25 additions and 10 deletions
|
|
@ -551,8 +551,8 @@ const initKernel = (initData) => {
|
||||||
writeLog('booted kernel process [pid=' + kernelProcessPid + ']')
|
writeLog('booted kernel process [pid=' + kernelProcessPid + ']')
|
||||||
|
|
||||||
kernelProcess.on('close', (code) => {
|
kernelProcess.on('close', (code) => {
|
||||||
|
writeLog(`kernel exited with code [${code}]`)
|
||||||
if (0 !== code) {
|
if (0 !== code) {
|
||||||
writeLog(`kernel exited with code [${code}]`)
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 20:
|
case 20:
|
||||||
showErrorWindow('⚠️ 数据库被锁定 The database is locked',
|
showErrorWindow('⚠️ 数据库被锁定 The database is locked',
|
||||||
|
|
|
||||||
|
|
@ -32,16 +32,26 @@ func HookResident() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for range time.Tick(time.Second * 30) {
|
for range time.Tick(time.Second * 30) {
|
||||||
if 0 == util.CountSessions() {
|
if makeSureSessionEmpty() {
|
||||||
time.Sleep(time.Second * 7)
|
logging.LogInfof("no active session, exit kernel process now")
|
||||||
if 0 == util.CountSessions() {
|
Close(false, 1)
|
||||||
logging.LogInfof("no active session, exit kernel process now")
|
|
||||||
Close(false, 1)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func makeSureSessionEmpty() bool {
|
||||||
|
count := 0
|
||||||
|
for i := 0; i < 7; i++ {
|
||||||
|
count = util.CountSessions()
|
||||||
|
//logging.LogDebugf("session count [%d]", count)
|
||||||
|
if 0 < count {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second * 1)
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
func HandleSignal() {
|
func HandleSignal() {
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
signal.Notify(c, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,7 @@ func serveWebSocket(ginServer *gin.Engine) {
|
||||||
})
|
})
|
||||||
|
|
||||||
util.WebSocketServer.HandlePong(func(session *melody.Session) {
|
util.WebSocketServer.HandlePong(func(session *melody.Session) {
|
||||||
//model.Logger.Debugf("pong")
|
//logging.LogInfof("pong")
|
||||||
})
|
})
|
||||||
|
|
||||||
util.WebSocketServer.HandleConnect(func(s *melody.Session) {
|
util.WebSocketServer.HandleConnect(func(s *melody.Session) {
|
||||||
|
|
@ -337,9 +337,14 @@ func serveWebSocket(ginServer *gin.Engine) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !authOk {
|
||||||
|
// 用于授权页保持连接,避免非常驻内存内核自动退出 https://github.com/siyuan-note/insider/issues/1099
|
||||||
|
authOk = strings.Contains(s.Request.RequestURI, "/ws?app=siyuan&id=auth")
|
||||||
|
}
|
||||||
|
|
||||||
if !authOk {
|
if !authOk {
|
||||||
s.CloseWithMsg([]byte(" unauthenticated"))
|
s.CloseWithMsg([]byte(" unauthenticated"))
|
||||||
//logging.LogWarnf("closed a unauthenticated session [%s]", util.GetRemoteAddr(s))
|
//logging.LogWarnf("closed an unauthenticated session [%s]", util.GetRemoteAddr(s))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -351,7 +356,7 @@ func serveWebSocket(ginServer *gin.Engine) {
|
||||||
util.WebSocketServer.HandleDisconnect(func(s *melody.Session) {
|
util.WebSocketServer.HandleDisconnect(func(s *melody.Session) {
|
||||||
util.RemovePushChan(s)
|
util.RemovePushChan(s)
|
||||||
//sessionId, _ := s.Get("id")
|
//sessionId, _ := s.Get("id")
|
||||||
//model.Logger.Debugf("ws [%s] disconnected", sessionId)
|
//logging.LogInfof("ws [%s] disconnected", sessionId)
|
||||||
})
|
})
|
||||||
|
|
||||||
util.WebSocketServer.HandleError(func(s *melody.Session, err error) {
|
util.WebSocketServer.HandleError(func(s *melody.Session, err error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue