Browse Source

in progress

0x4a52466c696e74 1 year ago
parent
commit
fa60bebc05
1 changed files with 4 additions and 1 deletions
  1. 4 1
      rest_websocket/socket.go

+ 4 - 1
rest_websocket/socket.go

@@ -59,6 +59,10 @@ func (s *Socket) read() {
 	//defer log.Println("work close...")
 	// контекст
 	s.ctx, s.cancel = context.WithCancel(context.Background())
+	defer func() {
+		s.cancel()
+		s.conn.Close()
+	}()
 	// создаем канал для обработки входящих сообщений
 	chIn := s.exec()
 	for {
@@ -74,7 +78,6 @@ func (s *Socket) read() {
 			// Обработка текстового или бинарного сообщения
 			req, err := rest.ReadRequestStream(r)
 			if err != nil {
-				s.conn.Close()
 				log.Println("data error: ", err)
 				return
 			}