From 23a348b4f768f1b26bd496f2b5219f430aa36832 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Tue, 22 Aug 2017 08:49:44 -0700 Subject: [PATCH] periodically ping client from server --- server/stream.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/server/stream.go b/server/stream.go index 33bef477..2bc038d0 100644 --- a/server/stream.go +++ b/server/stream.go @@ -224,6 +224,10 @@ func EventStreamSSE(c *gin.Context) { return } + // ping the client + io.WriteString(rw, ": ping\n\n") + flusher.Flush() + logrus.Debugf("user feed: connection opened") user := session.User(c) @@ -269,6 +273,9 @@ func EventStreamSSE(c *gin.Context) { return case <-ctx.Done(): return + case <-time.After(time.Second * 30): + io.WriteString(rw, ": ping\n\n") + flusher.Flush() case buf, ok := <-eventc: if ok { io.WriteString(rw, "data: ") @@ -294,6 +301,9 @@ func LogStreamSSE(c *gin.Context) { return } + io.WriteString(rw, ": ping\n\n") + flusher.Flush() + // repo := session.Repo(c) // // // parse the build number and job sequence number from @@ -388,6 +398,9 @@ func LogStreamSSE(c *gin.Context) { return case <-ctx.Done(): return + case <-time.After(time.Second * 30): + io.WriteString(rw, ": ping\n\n") + flusher.Flush() case buf, ok := <-logc: if ok { if id > last {