Caddy 0.9.5
I'm using Caddy as a reverse proxy:
localhost:81 {
proxy / localhost:8082
}
On localhost:8082 there is an app that does some processing before it returns a result. When the browser aborts the connection, the processing is stopped. This can be simulated with this simple Go app:
package main
import "net/http"
import "log"
import "time"
func main() {
http.HandleFunc("/", handleRequest)
http.ListenAndServe("0.0.0.0:8082", nil)
}
func handleRequest(w http.ResponseWriter, r *http.Request) {
cn := w.(http.CloseNotifier)
cc := cn.CloseNotify()
go func() {
<-cc
log.Println("Closed!")
}()
time.Sleep(5 * time.Second)
}
When I go directly to http://localhost:8082/ and then hit "Cancel" in the browser before the 5 seconds have passed, the app prints "Closed!" on the console.
When I go to http://localhost:81/ where Caddy is listening and hit "Cancel" in the browser, it does not print "Closed!", the upstream request is allowed to run to completion.
This is a problem in cases like search-as-you-type where requests are frequently canceled when new user input is available. The backend should get informed, so it can immediately stop creating a result that will be discarded anyway.
Related to this commit fixing #1345.
Hm, that's interesting. Does someone want to look into this? @tpng would you be able to?
I see in the PR #1358 the issue was being thought of already.
"Anyway if you think it is necessary to cancel the outgoing request if the incoming request is cancelled. I will revise this patch a bit."
Let see if @tw4452852 would like to work on it. :wink:
Ah, I had missed that comment! Haha, Tw, can I assign you to this? :smile:
Got it! I will work out a patch recently.
Most helpful comment
Got it! I will work out a patch recently.