AOSSIE-Org / AOSSIE-Org/Ell-ena
BUG:AI requests can hang indefinitely due to missing timeout handling
- Dominant language
- Dart
- Stars
- 54
- Forks
- 110
- PR merge metrics
- No merged PRs in 30d
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### What happened?
Description
The Gemini API requests in lib/services/ai_service.dart currently do not implement timeout handling for HTTP requests.
If the network becomes unstable or the Gemini API becomes unresponsive, the application may continue waiting indefinitely for a response.
This issue affects the following methods:
generateChatResponse()
handleToolResponse()
Expected Behavior
AI requests should fail gracefully after a reasonable timeout duration and provide an appropriate error message to the user.
Actual Behavior
Requests may remain pending indefinitely under unstable or interrupted network conditions, potentially causing:
infinite loading states
frozen AI chat interactions
blocked user workflow
repeated retry attempts by users
Steps to Reproduce
Open the AI chat feature
Send a message to trigger a Gemini API request
Disable or interrupt the internet connection while the request is in progress
Observe that the request may never complete
Root Cause
The HTTP requests use http.post() without a .timeout() constraint, allowing requests to wait indefinitely if the server or network does not respond.
Suggested Fix
Add timeout handling to the HTTP requests:
await http.post(...).timeout(
const Duration(seconds: 30),
);
Additionally, handle TimeoutException separately to provide graceful error feedback to the user.
Possible Impact
Poor user experience during unstable connectivity
Infinite loading indicators
Unresponsive AI chat behavior
Increased likelihood of duplicate retry requests
### Record
- [x] I agree to follow this project's Code of Conduct
- [x] I want to work on this issue
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.