mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #84693 from yutedz/watching-stop
Stop Watching when there is encoding error
This commit is contained in:
commit
7c7ae977d5
@ -285,10 +285,12 @@ func (s *WatchServer) HandleWS(ws *websocket.Conn) {
|
|||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
streamBuf := &bytes.Buffer{}
|
streamBuf := &bytes.Buffer{}
|
||||||
ch := s.Watching.ResultChan()
|
ch := s.Watching.ResultChan()
|
||||||
|
|
||||||
|
defer s.Watching.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
s.Watching.Stop()
|
|
||||||
return
|
return
|
||||||
case event, ok := <-ch:
|
case event, ok := <-ch:
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -317,25 +319,21 @@ func (s *WatchServer) HandleWS(ws *websocket.Conn) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
utilruntime.HandleError(fmt.Errorf("unable to convert watch object: %v", err))
|
utilruntime.HandleError(fmt.Errorf("unable to convert watch object: %v", err))
|
||||||
// client disconnect.
|
// client disconnect.
|
||||||
s.Watching.Stop()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := s.Encoder.Encode(outEvent, streamBuf); err != nil {
|
if err := s.Encoder.Encode(outEvent, streamBuf); err != nil {
|
||||||
// encoding error
|
// encoding error
|
||||||
utilruntime.HandleError(fmt.Errorf("unable to encode event: %v", err))
|
utilruntime.HandleError(fmt.Errorf("unable to encode event: %v", err))
|
||||||
s.Watching.Stop()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if s.UseTextFraming {
|
if s.UseTextFraming {
|
||||||
if err := websocket.Message.Send(ws, streamBuf.String()); err != nil {
|
if err := websocket.Message.Send(ws, streamBuf.String()); err != nil {
|
||||||
// Client disconnect.
|
// Client disconnect.
|
||||||
s.Watching.Stop()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if err := websocket.Message.Send(ws, streamBuf.Bytes()); err != nil {
|
if err := websocket.Message.Send(ws, streamBuf.Bytes()); err != nil {
|
||||||
// Client disconnect.
|
// Client disconnect.
|
||||||
s.Watching.Stop()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user