Open voctior opened 1 year ago
i have a demo like this. I guess it's this mistake
import "testing"
type TT struct {
t *TT
c int
}
func TestXxx(t *testing.T) {
var a = TT{t: &TT{c: 1}}
A(a.t)
if a.t.c != 2 {
panic(a.t.c)
}
B(a.t)
if a.t.c != 6 {
panic(a.t.c)
}
}
func A(in *TT) {
in.c++
in = &TT{c: 6}
}
func B(in *TT) {
in.c = 6
}
test has no panic
I want to use response-finishRequest to delete locally mixed files .like this
fix like this?
// ochttp
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var tags addedTags
r2, traceEnd := h.startTrace(w, r)
defer traceEnd()
w, statsEnd := h.startStats(w, r2)
defer statsEnd(&tags)
handler := h.Handler
if handler == nil {
handler = http.DefaultServeMux
}
r2 = r2.WithContext(context.WithValue(r.2Context(), addedTagsKey{}, &tags))
// value copy
*r = *r2
handler.ServeHTTP(w, r)
}
Please answer these questions before submitting a bug report.
What version of OpenCensus are you using?
v0.24.0
What version of Go are you using?
go version go1.19.2 darwin/arm64
What did you do?
// ochttp func (h Handler) ServeHTTP(w http.ResponseWriter, r http.Request) { var tags addedTags // ----- shallow copy r, traceEnd := h.startTrace(w, r) defer traceEnd() w, statsEnd := h.startStats(w, r) defer statsEnd(&tags) handler := h.Handler if handler == nil { handler = http.DefaultServeMux } // ----- shallow copy r = r.WithContext(context.WithValue(r.Context(), addedTagsKey{}, &tags)) handler.ServeHTTP(w, r) }
// std http func (c *conn) serve(ctx context.Context){ // w.req has not change serverHandler{c.server}.ServeHTTP(w, w.req) w.finishRequest() }
What did you expect to see?
w.req has changed
What did you see instead?
Additional context
Add any other context about the problem here.