revert usage of context

Signed-off-by: Robert Landers <landers.robert@gmail.com>
This commit is contained in:
Robert Landers
2025-11-25 17:53:28 +01:00
parent c2124e806f
commit 0a56469fd8
3 changed files with 8 additions and 9 deletions

View File

@@ -7,7 +7,6 @@ import (
) )
func acquireSemaphoreWithAdmissionControl( func acquireSemaphoreWithAdmissionControl(
ctx context.Context,
sem *semaphore.Weighted, sem *semaphore.Weighted,
scaleChan chan *frankenPHPContext, scaleChan chan *frankenPHPContext,
fc *frankenPHPContext, fc *frankenPHPContext,
@@ -17,7 +16,7 @@ func acquireSemaphoreWithAdmissionControl(
} }
if maxWaitTime > 0 && scaleChan != nil { if maxWaitTime > 0 && scaleChan != nil {
ct, cancel := context.WithTimeout(ctx, minStallTime) ct, cancel := context.WithTimeout(context.Background(), minStallTime)
err := sem.Acquire(ct, 1) err := sem.Acquire(ct, 1)
cancel() cancel()
@@ -27,7 +26,7 @@ func acquireSemaphoreWithAdmissionControl(
default: default:
} }
ctx, cancel := context.WithTimeout(ctx, maxWaitTime) ctx, cancel := context.WithTimeout(context.Background(), maxWaitTime)
defer cancel() defer cancel()
if err := sem.Acquire(ctx, 1); err != nil { if err := sem.Acquire(ctx, 1); err != nil {
@@ -39,7 +38,7 @@ func acquireSemaphoreWithAdmissionControl(
} }
if maxWaitTime > 0 { if maxWaitTime > 0 {
ctx, cancel := context.WithTimeout(ctx, maxWaitTime) ctx, cancel := context.WithTimeout(context.Background(), maxWaitTime)
defer cancel() defer cancel()
if err := sem.Acquire(ctx, 1); err != nil { if err := sem.Acquire(ctx, 1); err != nil {
@@ -50,7 +49,7 @@ func acquireSemaphoreWithAdmissionControl(
} }
if scaleChan != nil { if scaleChan != nil {
ctx, cancel := context.WithTimeout(ctx, minStallTime) ctx, cancel := context.WithTimeout(context.Background(), minStallTime)
err := sem.Acquire(ctx, 1) err := sem.Acquire(ctx, 1)
cancel() cancel()
@@ -60,14 +59,14 @@ func acquireSemaphoreWithAdmissionControl(
default: default:
} }
if err := sem.Acquire(ctx, 1); err != nil { if err := sem.Acquire(context.Background(), 1); err != nil {
return ErrMaxWaitTimeExceeded return ErrMaxWaitTimeExceeded
} }
} }
return nil return nil
} }
if err := sem.Acquire(ctx, 1); err != nil { if err := sem.Acquire(context.Background(), 1); err != nil {
return ErrMaxWaitTimeExceeded return ErrMaxWaitTimeExceeded
} }

View File

@@ -113,7 +113,7 @@ func handleRequestWithRegularPHPThreads(ch contextHolder) error {
metrics.StartRequest() metrics.StartRequest()
metrics.QueuedRequest() metrics.QueuedRequest()
if err := acquireSemaphoreWithAdmissionControl(ch.ctx, regularSemaphore, scaleChan, ch.frankenPHPContext); err != nil { if err := acquireSemaphoreWithAdmissionControl(regularSemaphore, scaleChan, ch.frankenPHPContext); err != nil {
ch.frankenPHPContext.reject(err) ch.frankenPHPContext.reject(err)
metrics.StopRequest() metrics.StopRequest()
return err return err

View File

@@ -258,7 +258,7 @@ func (worker *worker) handleRequest(ch contextHolder) error {
workerScaleChan = nil workerScaleChan = nil
} }
if err := acquireSemaphoreWithAdmissionControl(ch.ctx, worker.semaphore, workerScaleChan, ch.frankenPHPContext); err != nil { if err := acquireSemaphoreWithAdmissionControl(worker.semaphore, workerScaleChan, ch.frankenPHPContext); err != nil {
metrics.DequeuedWorkerRequest(worker.name) metrics.DequeuedWorkerRequest(worker.name)
ch.frankenPHPContext.reject(err) ch.frankenPHPContext.reject(err)
metrics.StopWorkerRequest(worker.name, time.Since(ch.frankenPHPContext.startedAt)) metrics.StopWorkerRequest(worker.name, time.Since(ch.frankenPHPContext.startedAt))