Problem:worker.ExecuteCodeAsync(request) is called without any CancellationToken linked to request.TimeoutSeconds. Roslyn's ExecuteFreePlayAsync only checks cancellation at the start, not around emit/invoke. If student code hangs (infinite loop, blocking I/O), nothing kills it.
Also ensure RoslynCodeExecutor checks the token periodically inside execution.
Acceptance criteria:
Infinite-loop student code is killed within TimeoutSeconds + small buffer
Test with while(true){} confirms cancellation
No regression for legitimate quick executions
**Severity:** High (resource safety)
**File:** `SpikerSoft.EventHandlers.CodeExecution/Services/CodeExecutionWorkerHostedService.cs` (~298)
**Problem:** `worker.ExecuteCodeAsync(request)` is called without any `CancellationToken` linked to `request.TimeoutSeconds`. Roslyn's `ExecuteFreePlayAsync` only checks cancellation at the start, not around emit/invoke. If student code hangs (infinite loop, blocking I/O), nothing kills it.
**Fix:**
```csharp
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(request.TimeoutSeconds));
using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, stoppingToken);
var response = await worker.ExecuteCodeAsync(request, linkedCts.Token);
```
Also ensure `RoslynCodeExecutor` checks the token periodically inside execution.
**Acceptance criteria:**
- [ ] Infinite-loop student code is killed within `TimeoutSeconds + small buffer`
- [ ] Test with `while(true){}` confirms cancellation
- [ ] No regression for legitimate quick executions
CodeExecutionWorkerHostedService now enforces request.TimeoutSeconds per message:
Captured stoppingToken into _shutdownToken field at ExecuteAsync start
In OnCodeExecutionRequestReceived, builds a CancellationTokenSource(timeout) linked with _shutdownToken
request.TimeoutSeconds is clamped to [1, 300] via MaxExecutionTimeout = 5 minutes to bound worst-case worker load even if a misconfigured client claims an enormous timeout
worker.ExecuteCodeAsync(request, linkedCts.Token) now receives the linked token
OperationCanceledException from a tripped timeout is caught and turned into a CodeExecutionResponse with Success = false and a clear error message
**Resolved.**
`CodeExecutionWorkerHostedService` now enforces `request.TimeoutSeconds` per message:
- Captured `stoppingToken` into `_shutdownToken` field at `ExecuteAsync` start
- In `OnCodeExecutionRequestReceived`, builds a `CancellationTokenSource(timeout)` linked with `_shutdownToken`
- `request.TimeoutSeconds` is clamped to `[1, 300]` via `MaxExecutionTimeout = 5 minutes` to bound worst-case worker load even if a misconfigured client claims an enormous timeout
- `worker.ExecuteCodeAsync(request, linkedCts.Token)` now receives the linked token
- `OperationCanceledException` from a tripped timeout is caught and turned into a `CodeExecutionResponse` with `Success = false` and a clear error message
File: `SpikerSoft.EventHandlers.CodeExecution/Services/CodeExecutionWorkerHostedService.cs`.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Severity: High (resource safety)
File:
SpikerSoft.EventHandlers.CodeExecution/Services/CodeExecutionWorkerHostedService.cs(~298)Problem:
worker.ExecuteCodeAsync(request)is called without anyCancellationTokenlinked torequest.TimeoutSeconds. Roslyn'sExecuteFreePlayAsynconly checks cancellation at the start, not around emit/invoke. If student code hangs (infinite loop, blocking I/O), nothing kills it.Fix:
Also ensure
RoslynCodeExecutorchecks the token periodically inside execution.Acceptance criteria:
TimeoutSeconds + small bufferwhile(true){}confirms cancellationResolved.
CodeExecutionWorkerHostedServicenow enforcesrequest.TimeoutSecondsper message:stoppingTokeninto_shutdownTokenfield atExecuteAsyncstartOnCodeExecutionRequestReceived, builds aCancellationTokenSource(timeout)linked with_shutdownTokenrequest.TimeoutSecondsis clamped to[1, 300]viaMaxExecutionTimeout = 5 minutesto bound worst-case worker load even if a misconfigured client claims an enormous timeoutworker.ExecuteCodeAsync(request, linkedCts.Token)now receives the linked tokenOperationCanceledExceptionfrom a tripped timeout is caught and turned into aCodeExecutionResponsewithSuccess = falseand a clear error messageFile:
SpikerSoft.EventHandlers.CodeExecution/Services/CodeExecutionWorkerHostedService.cs.