valyala/fasthttp

Improve RequestCtx context documentation

Geschlossen

#1.219 geöffnet am 16.02.2022

 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)Go (1.755 Forks)batch import
help wantedpending/development

Repository-Metriken

Stars
 (21.741 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 3T) (44 gemergte PRs in 30 T)

Beschreibung

The context doesnt become Done() on the timeout.

for example, this code:

func main() {
	fasthttp.ListenAndServe(":8080", fasthttp.TimeoutHandler(func(ctx *fasthttp.RequestCtx) {
		log.Println("begin")

		tm := time.NewTimer(10 * time.Second)

		select {
		case <-ctx.Done():
			log.Println("context cancelled")
			return
		case <-tm.C:
			log.Println("process finished ok")
		}

		log.Println("end")
	}, time.Second*2, "timeout"))
}

prints:

2022/02/16 12:52:56 begin
2022/02/16 12:53:06 process finished ok
2022/02/16 12:53:06 end

The client receives the timeout after 2 seconds, and the handler finishes after 10 seconds yet. It would be nice if the context became Done() in this case. If this would break existing code expectations then it can be made optional (via setting or a new TimeoutHandlerWithShutdown or something like it).

Will you accept a PR for this?

Contributor Guide