mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
prevent hanging event source connections
This commit is contained in:
parent
b3951043a0
commit
2e9786c68e
2 changed files with 18 additions and 10 deletions
|
@ -88,12 +88,16 @@
|
||||||
|
|
||||||
events = new EventSource("/api/stream/" + repo + "?access_token=" + token, { withCredentials: true });
|
events = new EventSource("/api/stream/" + repo + "?access_token=" + token, { withCredentials: true });
|
||||||
events.onmessage = function (event) {
|
events.onmessage = function (event) {
|
||||||
console.log(event);
|
|
||||||
if (callback !== undefined) {
|
if (callback !== undefined) {
|
||||||
callback(angular.fromJson(event.data));
|
callback(angular.fromJson(event.data));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
events.onerror = function (event) {
|
events.onerror = function (event) {
|
||||||
|
callback = undefined;
|
||||||
|
if (events !== undefined) {
|
||||||
|
events.close();
|
||||||
|
events = undefined;
|
||||||
|
}
|
||||||
console.log('user event stream closed due to error.', event);
|
console.log('user event stream closed due to error.', event);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
22
server/ws.go
22
server/ws.go
|
@ -49,17 +49,21 @@ func GetRepoEvents(c *gin.Context) {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
c.Stream(func(w io.Writer) bool {
|
c.Stream(func(w io.Writer) bool {
|
||||||
event := <-eventc
|
select {
|
||||||
if event == nil {
|
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
|
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
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue