fix: concurrent write to single WebSocket connection (#392)

This commit is contained in:
UUBulb 2024-07-17 10:06:23 +08:00 committed by GitHub
parent 34fedd91d2
commit f95191c8af
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View File

@ -120,7 +120,7 @@ func (m *Monitor) AfterFind(tx *gorm.DB) error {
// IsServiceSentinelNeeded 判断该任务类型是否需要进行服务监控 需要则返回true // IsServiceSentinelNeeded 判断该任务类型是否需要进行服务监控 需要则返回true
func IsServiceSentinelNeeded(t uint64) bool { func IsServiceSentinelNeeded(t uint64) bool {
return t != TaskTypeCommand && t != TaskTypeTerminal && t != TaskTypeUpgrade return t != TaskTypeCommand && t != TaskTypeTerminalGRPC && t != TaskTypeUpgrade
} }
func (m *Monitor) InitSkipServers() error { func (m *Monitor) InitSkipServers() error {

View File

@ -28,6 +28,12 @@ func (conn *Conn) Write(data []byte) (int, error) {
return len(data), nil return len(data), nil
} }
func (conn *Conn) WriteMessage(messageType int, data []byte) error {
conn.writeLock.Lock()
defer conn.writeLock.Unlock()
return conn.Conn.WriteMessage(messageType, data)
}
func (conn *Conn) Read(data []byte) (int, error) { func (conn *Conn) Read(data []byte) (int, error) {
if len(conn.dataBuf) > 0 { if len(conn.dataBuf) > 0 {
n := copy(data, conn.dataBuf) n := copy(data, conn.dataBuf)