apache / skywalking

APM, Application Performance Monitoring System
https://skywalking.apache.org/
Apache License 2.0
23.9k stars 6.53k forks source link

[Bug] met a interface conversion panic of skywalking.http.flush problem #12616

Closed akilichen closed 2 months ago

akilichen commented 2 months ago

Search before asking

Apache SkyWalking Component

Go Agent (apache/skywalking-go)

What happened

I am using the standard package named httputil with its NewSingleHostReverseProxy function, here is the error messages encountered.

panic: interface conversion: *mux.skywalking_operatorTypeMuxwriterWrapper is not http.Flusher: missing method Flush

goroutine 62 [running]:
github.com/gin-gonic/gin.(*responseWriter).Flush(0xc0001a2500?)
        /app/go-project/ms-gateway/vendor/github.com/gin-gonic/gin/response_writer.go:118 +0x59
net/http/httputil.(*maxLatencyWriter).delayedFlush(0xc0006939b0)
        /usr/local/go/src/net/http/httputil/reverseproxy.go:546 +0x95
created by time.goFunc
        /usr/local/go/src/time/sleep.go:176 +0x32

here is my code.

        proxy := httputil.NewSingleHostReverseProxy(remote) // remote mean target host.
    //Define the director func
    urlPath := c.Param("proxyPath")
    proxy.Director = func(req *orginHttp.Request) {
        req.Header = c.Request.Header
        req.Host = remote.Host
        req.URL.Scheme = remote.Scheme
        req.URL.Host = remote.Host
        req.URL.Path = c.Request.URL.Path
        // some code operation here
        ......
    }
    proxy.ServeHTTP(c.Writer, c.Request)

something else: the sw-agent version is v0.3.0 with go1.19.

What you expected to happen

fix the bug! Is the httputil reverse proxy not supported by SW, or something I did wrong? What should I do?

How to reproduce

see What happened

Anything else

If anything I do not explain clearly, leave me a message. Thanks!

Are you willing to submit a pull request to fix on your own?

Code of Conduct