valyala / fasthttp

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http
MIT License
21.91k stars 1.76k forks source link

fix RequestCtx is canceled (#1879) #1890

Closed ksw2000 closed 3 weeks ago

ksw2000 commented 4 weeks ago

In my opinion, the root cause of issue #1879 is that the done channel in ctx.s is nil. We can simply create done channel in fakeServer during the initialization of RequestCtx.

Original

requestCtx.Init()
→ ctx.Init2
→ ctx.s = fakeServer        (the ctx.s.done is nil)

requestCtx.Err()
→ ctx.Done()        (generate the new buffered channel and send struct{}{} since the ctx.s.done is nil)
→ error is returned

Fix

requestCtx.Init()
→ ctx.Init2
→ ctx.s = fakeServer        (the ctx.s.done is initialized)

requestCtx.Err()
→ ctx.Done()        (return ctx.s.done since it is non nil)
→ error is nil
erikdubbelboer commented 3 weeks ago

Thanks, I like it!