r3labs / sse

Server Sent Events server and client for Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CloseNotify() incompatible with the Labstack Echo v4:

externaljdev opened this issue · comments

CloseNotify() is deprecated in Go and completely removed in Echo 4 (from January 2019!)
https://pkg.go.dev/net/http#CloseNotifier

2021/07/15 12:30:48 http: panic serving 127.0.0.1:33340: interface conversion: *echo.Response is not http.CloseNotifier: missing method CloseNotify
goroutine 34 [running]:
net/http.(*conn).serve.func1
        /usr/lib/go/src/net/http/server.go:1824
panic(0xbff920, 0xc000384390)
        /usr/lib/go/src/runtime/panic.go:971
github.com/r3labs/sse/v2.(*Server).HTTPHandle
        ~/go/pkg/mod/github.com/r3labs/sse/v2@v2.3.3/http.go:61

Removing from http.go fixes it with no apparent loss of functionality (but not extensively tested yet):

    notify := w.(http.CloseNotifier).CloseNotify()                                                                                                       
    go func() {                                                                                                                                          
        <-notify                                                                                                                                         
        sub.close()                                                                                                                                      
    }()   

Version 4 of echo removed support for CloseNotify().. about 2.5 years ago: labstack/echo#1269

"It was already NOT working (not sending signals) as of 1.11, the functionality was gone already, we merely deleted the functions that exposed it. If everyone still rely on it they should migrate to using c.Request().Context().Done() instead."

Hi @externaljdev

Thanks for raising the issue. This should be fixed in v2.3.4