Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: rejects closed connections right away #1407

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions frankenphp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions threadregular.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Loading