From c0aefddb1ee75d4d0a36d8db197755469687bfc8 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Mon, 31 Jul 2023 18:21:31 +0200 Subject: panic when data to send to a client can not be marshaled --- connection.go | 11 ++++------- main.go | 6 +----- wrms.go | 4 ++-- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/connection.go b/connection.go index 4901fdd..e16c942 100644 --- a/connection.go +++ b/connection.go @@ -67,12 +67,11 @@ func (c *Connection) Send(ev Event) { c.refs.Add(-1) } -func (conn *Connection) _send(evs []interface{}) error { +func (conn *Connection) _send(evs []interface{}) { for _, ev := range evs { data, err := json.Marshal(ev) if err != nil { - llog.Warning("Encoding the initial command %v failed with %s", ev, err) - return err + llog.Fatal("Encoding the initial command %v failed with %s", ev, err) } sdata := string(data) @@ -80,12 +79,10 @@ func (conn *Connection) _send(evs []interface{}) error { fmt.Fprintf(conn.w, "data: %s\n\n", sdata) conn.flusher.Flush() } - - return nil } -func (conn *Connection) _sendEv(ev Event) error { - return conn._send([]interface{}{ev}) +func (conn *Connection) _sendEv(ev Event) { + conn._send([]interface{}{ev}) } func (conn *Connection) serve() { diff --git a/main.go b/main.go index 0b9b956..c2642f7 100644 --- a/main.go +++ b/main.go @@ -243,11 +243,7 @@ func eventsEndpoint(w http.ResponseWriter, r *http.Request) { }() llog.Info("New SSE connection with id %v", connId) - err = wrms.initConn(conn) - if err != nil { - return - } - + wrms.initConn(conn) conn.serve() } diff --git a/wrms.go b/wrms.go index b2bc2dc..41d7549 100644 --- a/wrms.go +++ b/wrms.go @@ -77,7 +77,7 @@ func (wrms *Wrms) delConn(conn *Connection) { } } -func (wrms *Wrms) initConn(conn *Connection) error { +func (wrms *Wrms) initConn(conn *Connection) { wrms.rwlock.RLock() curEventId := wrms.eventId.Load() @@ -123,7 +123,7 @@ func (wrms *Wrms) initConn(conn *Connection) error { wrms.rwlock.RUnlock() llog.Info("Sending initial cmds %v", initialCmds) - return conn._send(initialCmds) + conn._send(initialCmds) } func (wrms *Wrms) GetConn(connId uuid.UUID) *Connection { -- cgit v1.2.3