fix(quizzes): add configurable timeout to AI service fetch - #85
Merged
DeFiVC merged 1 commit intoJul 23, 2026
Merged
Conversation
The fetch call to the AI service in ai-client.ts had no AbortController or timeout configuration. If the AI service hangs, the request blocks indefinitely, holding open sockets and event loop references. Under AI service degradation this can exhaust available sockets. Add AbortController with a configurable timeout (default 30s) via the new AI_TIMEOUT_MS environment variable. The timeout error is caught, logged, and re-thrown so the existing fallback in quizService.generateQuiz continues to work. Closes ChainLearnOfficial#74
DeFiVC
approved these changes
Jul 23, 2026
DeFiVC
left a comment
Contributor
There was a problem hiding this comment.
Looks good. Clean AbortController pattern, proper cleanup in finally, and the timeout error integrates with the existing fallback in quizService.generateQuiz. CI is green, description is thorough. Approved.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #74
Type of Change
Summary
The
fetchcall to the AI service inai-client.tshad noAbortControlleror timeout configuration. If the AI service hangs, the request blocks indefinitely, holding open sockets and event loop references. Under AI service degradation, this can exhaust available sockets.This PR adds an
AbortControllerwith a configurable timeout (default 30s) via the newAI_TIMEOUT_MSenvironment variable. Hung connections are now cleaned up and a meaningful error is thrown.Motivation / Context
Fixes #74 — under AI service degradation, hung fetch connections keep Node.js event loop references and sockets open, which can exhaust resources. The existing fallback in
quizService.generateQuizcatches errors and falls back to placeholder questions, but couldn't handle hung connections.Detailed Changes
src/config/index.ts:AI_TIMEOUT_MSenv var withz.coerce.number().default(30_000)— configurable per environmentsrc/modules/quizzes/ai-client.ts:AbortControllerusingconfig.AI_TIMEOUT_MSsignal: controller.signalto the fetch optionsAbortErrorand throw a descriptive timeout errorfinallyblock to clear the timeout timer on success or failureTesting
async-lockmodule error unrelated)