Compare commits

...

2 Commits

Author SHA1 Message Date
0c5ddac9f5 프로세스 종료 안되는 문제 수정 2024-02-15 12:06:31 +09:00
c08a3abf83 prometheus metric 오류 처리 2024-02-15 12:06:20 +09:00
2 changed files with 16 additions and 7 deletions

View File

@ -112,8 +112,10 @@ func (pe *prometheusExporter) loop(ctx context.Context) {
return return
case req := <-pe.writerChan: case req := <-pe.writerChan:
if m := collector.metrics[req.key]; m != nil { if collector != nil {
atomic.StoreUint64(m.valptr, math.Float64bits(req.val)) if m := collector.metrics[req.key]; m != nil {
atomic.StoreUint64(m.valptr, math.Float64bits(req.val))
}
} }
case nm := <-pe.registerChan: case nm := <-pe.registerChan:

View File

@ -50,8 +50,9 @@ type DownstreamMessage struct {
type commandType string type commandType string
const ( const (
commandType_EnterRoom = commandType("enter_room") commandType_EnterRoom = commandType("enter_room")
commandType_LeaveRoom = commandType("leave_room") commandType_LeaveRoom = commandType("leave_room")
ForceShutdownCloseMessage = "force_shutdown"
) )
type commandMessage struct { type commandMessage struct {
@ -302,6 +303,7 @@ func (ws *WebsocketHandler) mainLoop(ctx context.Context) {
logger.Println(r) logger.Println(r)
} }
}() }()
c.closeMessage = ForceShutdownCloseMessage
ws.ClientDisconnected(c) ws.ClientDisconnected(c)
c.Close() c.Close()
} }
@ -495,6 +497,11 @@ func upgrade_core(ws *WebsocketHandler, conn *websocket.Conn, accid primitive.Ob
ws.connWaitGroup.Add(1) ws.connWaitGroup.Add(1)
go func(c *wsconn, accid primitive.ObjectID, deliveryChan chan<- any) { go func(c *wsconn, accid primitive.ObjectID, deliveryChan chan<- any) {
defer func() {
recover()
ws.connWaitGroup.Done()
}()
for { for {
messageType, r, err := c.NextReader() messageType, r, err := c.NextReader()
if err != nil { if err != nil {
@ -519,10 +526,10 @@ func upgrade_core(ws *WebsocketHandler, conn *websocket.Conn, accid primitive.Ob
ws.Call(newconn.sender, string(cmd), r) ws.Call(newconn.sender, string(cmd), r)
} }
} }
ws.connWaitGroup.Done()
c.Conn = nil c.Conn = nil
ws.connInOutChan <- c if c.closeMessage != ForceShutdownCloseMessage {
ws.connInOutChan <- c
}
}(newconn, accid, ws.deliveryChan) }(newconn, accid, ws.deliveryChan)
} }