diff --git a/server/static/scripts/services/repos.js b/server/static/scripts/services/repos.js index 5fc306fa8..667951438 100644 --- a/server/static/scripts/services/repos.js +++ b/server/static/scripts/services/repos.js @@ -88,12 +88,16 @@ events = new EventSource("/api/stream/" + repo + "?access_token=" + token, { withCredentials: true }); events.onmessage = function (event) { - console.log(event); if (callback !== undefined) { callback(angular.fromJson(event.data)); } }; events.onerror = function (event) { + callback = undefined; + if (events !== undefined) { + events.close(); + events = undefined; + } console.log('user event stream closed due to error.', event); }; }; diff --git a/server/ws.go b/server/ws.go index 81165cf23..7a670642e 100644 --- a/server/ws.go +++ b/server/ws.go @@ -49,17 +49,21 @@ func GetRepoEvents(c *gin.Context) { }() c.Stream(func(w io.Writer) bool { - event := <-eventc - if event == nil { + select { + case event := <-eventc: + if event == nil { + log.Infof("nil event received") + return false + } + if event.Kind == eventbus.EventRepo && + event.Name == repo.FullName { + d := map[string]interface{}{} + json.Unmarshal(event.Msg, &d) + c.SSEvent("message", d) + } + case <-c.Writer.CloseNotify(): return false } - if event.Kind == eventbus.EventRepo && - event.Name == repo.FullName { - d := map[string]interface{}{} - json.Unmarshal(event.Msg, &d) - c.SSEvent("message", d) - } - return true }) }