AOSSIE-Org / AOSSIE-Org/Ell-ena

BUG:AI requests can hang indefinitely due to missing timeout handling

Aperta
#269 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Dart
Stelle
54
Fork
110
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.