(ch contextHolder)
| 132 | } |
| 133 | |
| 134 | func handleRequestWithRegularPHPThreads(ch contextHolder) error { |
| 135 | metrics.StartRequest() |
| 136 | |
| 137 | runtime.Gosched() |
| 138 | |
| 139 | if queuedRegularThreads.Load() == 0 { |
| 140 | regularThreadMu.RLock() |
| 141 | for _, thread := range regularThreads { |
| 142 | select { |
| 143 | case thread.requestChan <- ch: |
| 144 | regularThreadMu.RUnlock() |
| 145 | <-ch.frankenPHPContext.done |
| 146 | metrics.StopRequest() |
| 147 | |
| 148 | return nil |
| 149 | default: |
| 150 | // thread was not available |
| 151 | } |
| 152 | } |
| 153 | regularThreadMu.RUnlock() |
| 154 | } |
| 155 | |
| 156 | // if no thread was available, mark the request as queued and fan it out to all threads |
| 157 | queuedRegularThreads.Add(1) |
| 158 | metrics.QueuedRequest() |
| 159 | |
| 160 | for { |
| 161 | select { |
| 162 | case regularRequestChan <- ch: |
| 163 | queuedRegularThreads.Add(-1) |
| 164 | metrics.DequeuedRequest() |
| 165 | |
| 166 | <-ch.frankenPHPContext.done |
| 167 | metrics.StopRequest() |
| 168 | |
| 169 | return nil |
| 170 | case scaleChan <- ch.frankenPHPContext: |
| 171 | // the request has triggered scaling, continue to wait for a thread |
| 172 | case <-timeoutChan(maxWaitTime): |
| 173 | // the request has timed out stalling |
| 174 | queuedRegularThreads.Add(-1) |
| 175 | metrics.DequeuedRequest() |
| 176 | metrics.StopRequest() |
| 177 | |
| 178 | ch.frankenPHPContext.reject(ErrMaxWaitTimeExceeded) |
| 179 | |
| 180 | return ErrMaxWaitTimeExceeded |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | func attachRegularThread(thread *phpThread) { |
| 186 | regularThreadMu.Lock() |
no test coverage detected