Skip to content

Commit

Permalink
Ensure we don't modify a shared env (#452)
Browse files Browse the repository at this point in the history
* Ensure we don't modify a shared env

* Update worker.go

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

* Update worker.go

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>

---------

Co-authored-by: Kévin Dunglas <kevin@dunglas.fr>
  • Loading branch information
withinboredom and dunglas committed Dec 31, 2023
1 parent 2055142 commit 7830aae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,11 +452,10 @@ func ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) error

rc := requestChan
// Detect if a worker is available to handle this request
if nil == fc.responseWriter {
fc.env["FRANKENPHP_WORKER"] = "1"
} else if v, ok := workersRequestChans.Load(fc.scriptFilename); ok {
fc.env["FRANKENPHP_WORKER"] = "1"
rc = v.(chan *http.Request)
if nil != fc.responseWriter {
if v, ok := workersRequestChans.Load(fc.scriptFilename); ok {
rc = v.(chan *http.Request)
}
}

select {
Expand Down
6 changes: 6 additions & 0 deletions worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func startWorkers(fileName string, nbWorkers int, env map[string]string) error {
errs []error
)

if env == nil {
env = make(map[string]string, 1)
}

env["FRANKENPHP_WORKER"] = "1"

l := getLogger()
for i := 0; i < nbWorkers; i++ {
go func() {
Expand Down

0 comments on commit 7830aae

Please sign in to comment.