diff --git a/frankenphp.go b/frankenphp.go index f7c43277c..aa31be5d3 100644 --- a/frankenphp.go +++ b/frankenphp.go @@ -341,7 +341,7 @@ func Init(options ...Option) error { return err } - regularRequestChan = make(chan *http.Request, totalThreadCount-workerThreadCount) + regularRequestChan = make(chan *http.Request) regularThreads = make([]*phpThread, 0, totalThreadCount-workerThreadCount) for i := 0; i < totalThreadCount-workerThreadCount; i++ { thread := getInactivePHPThread() diff --git a/frankenphp_test.go b/frankenphp_test.go index 5f0d745e4..3d58b85e1 100644 --- a/frankenphp_test.go +++ b/frankenphp_test.go @@ -458,6 +458,9 @@ func TestConnectionAbort_worker(t *testing.T) { testConnectionAbort(t, &testOptions{workerScript: "connectionStatusLog.php"}) } func testConnectionAbort(t *testing.T, opts *testOptions) { + // Set parallel requests to 1 so the request will not get stalled and rejected immediately + opts.nbParallelRequests = 1 + testFinish := func(finish string) { t.Run(fmt.Sprintf("finish=%s", finish), func(t *testing.T) { logger, logs := observer.New(zapcore.InfoLevel) diff --git a/threadregular.go b/threadregular.go index 6a283087c..0deead21b 100644 --- a/threadregular.go +++ b/threadregular.go @@ -117,6 +117,10 @@ func handleRequestWithRegularPHPThreads(r *http.Request, fc *FrankenPHPContext) return case scaleChan <- fc: // the request has triggered scaling, continue to wait for a thread + continue + case <-r.Context().Done(): + // the request has been canceled by the client + return } } } diff --git a/worker.go b/worker.go index b366e37ea..72864a579 100644 --- a/worker.go +++ b/worker.go @@ -187,6 +187,10 @@ func (worker *worker) handleRequest(r *http.Request, fc *FrankenPHPContext) { return case scaleChan <- fc: // the request has triggered scaling, continue to wait for a thread + continue + case <-r.Context().Done(): + // the request has been canceled by the client + return } } }