Known Issues in http_interceptor
This document outlines the remaining issues found in the codebase that should be addressed for improved robustness and reliability.
🔧 Issues by Priority
High Priority Issues
1. Potential Memory Leak: Timer Not Always Cancelled
Location: lib/http/intercepted_client.dart lines 340-348
Status: ⚠️ Needs Investigation
Issue: The timeout timer might not be cancelled in all code paths, potentially causing memory leaks.
timeoutTimer = Timer(requestTimeout!, () {
// ... timeout logic ...
});
requestFuture.then((streamResponse) {
timeoutTimer?.cancel(); // ✅ Cancelled here
// ... code ...
}).catchError((error) {
timeoutTimer?.cancel(); // ✅ Cancelled here
// ... code ...
});
Risk: If the completer is completed through the timeout callback, the timer might not be cancelled in all scenarios.
Suggested Fix: Ensure timer cancellation in all completion paths and add proper cleanup.
2. Race Condition: Completer State Management
Location: lib/http/intercepted_client.dart lines 310-350
Status: ⚠️ Needs Investigation
Issue: Multiple code paths can complete the same completer, potentially causing race conditions.
if (!completer.isCompleted) {
completer.complete(response);
}
Risk: Multiple threads or async operations could try to complete the same completer simultaneously.
Suggested Fix: Add proper synchronization or use atomic operations for completer state management.
Medium Priority Issues
3. Potential Null Reference: Request Body Handling
Location: lib/http/intercepted_client.dart lines 240-251
Status: 🔧 Needs Improvement
Issue: The body type checking doesn't handle all possible null cases properly.
if (body != null) {
if (body is String) {
request.body = body;
} else if (body is List) {
request.bodyBytes = body.cast<int>(); // ❌ Could fail if List is null
} else if (body is Map) {
request.bodyFields = body.cast<String, String>(); // ❌ Could fail if Map is null
} else {
throw ArgumentError('Invalid request body "$body".');
}
}
Suggested Fix: Add null checks and better type validation.
4. Inconsistent Error Handling: StreamedResponse Type Check
Location: lib/http/intercepted_client.dart lines 220-227
Status: 🔧 Needs Improvement
Issue: The type check for StreamedResponse throws a generic ClientException instead of a more specific error.
if (interceptedResponse is StreamedResponse) {
return interceptedResponse;
}
throw ClientException(
'Expected `StreamedResponse`, got ${interceptedResponse.runtimeType}.',
);
Impact: This makes debugging harder as the error message doesn't provide enough context.
Suggested Fix: Create a more specific exception type or improve error messages.
5. Potential Issue: URL Parameter Encoding
Location: lib/utils/query_parameters.dart lines 42-60
Status: 🔧 Needs Investigation
Issue: The URL parameter encoding logic might not handle all edge cases properly.
parameters.forEach((key, value) {
final encodedKey = Uri.encodeQueryComponent(key);
if (value is List) {
// ... list handling ...
} else if (value is String) {
url += "$encodedKey=${Uri.encodeQueryComponent(value)}&";
} else {
url += "$encodedKey=${Uri.encodeQueryComponent(value.toString())}&";
}
});
Risk: If value.toString() returns null or throws an exception, this could cause issues.
Suggested Fix: Add proper null checks and exception handling.
Low Priority Issues
6. Potential Issue: Retry Policy State Management
Location: lib/http/intercepted_client.dart lines 360-380
Status: 🔧 Needs Improvement
Issue: The retry count is reset for each new request, but there's no validation that retry attempts don't exceed reasonable limits.
_retryCount = 0; // Reset retry count for each new request
Risk: A malicious retry policy could cause infinite loops or excessive retries.
Suggested Fix: Add maximum retry limits and validation.
7. Minor Issue: Inconsistent Exception Types
Location: lib/models/http_interceptor_exception.dart
Status: 🔧 Needs Improvement
Issue: The custom exception class uses dynamic for the message, which could lead to type safety issues.
class HttpInterceptorException implements Exception {
final dynamic message; // ❌ Should be String?
HttpInterceptorException([this.message]);
}
Suggested Fix: Change to String? for better type safety.
8. Potential Issue: Extension Type Safety
Location: lib/extensions/base_request.dart lines 15-70
Status: 🔧 Needs Improvement
Issue: The copyWith method uses dynamic for the body parameter, which could cause runtime errors.
BaseRequest copyWith({
// ... other parameters ...
dynamic body, // ❌ Should be more specific
// ... other parameters ...
}) {
// ... implementation ...
}
Suggested Fix: Use more specific types or add runtime type checking.
9. Minor Issue: Missing Validation in HTTP Methods
Location: lib/http/http_methods.dart lines 15-29
Status: 🔧 Needs Improvement
Issue: The fromString method doesn't handle case-insensitive parsing or trim whitespace.
static HttpMethod fromString(String method) {
switch (method) { // ❌ Case-sensitive, no trimming
case "HEAD":
return HttpMethod.HEAD;
// ... other cases ...
}
throw ArgumentError.value(method, "method", "Must be a valid HTTP Method.");
}
Suggested Fix: Add case-insensitive parsing and whitespace trimming.
🧪 Testing Issues
Test Coverage Gaps
10. Missing Edge Case Tests
Status: 📝 Needs Additional Tests
Areas needing more test coverage:
- Timer cancellation edge cases
- Completer race condition scenarios
- Null body handling
- Malformed URL parameter handling
- Retry policy edge cases
- Exception type validation
Suggested Action: Add comprehensive edge case tests for all identified issues.
📋 Action Items
Immediate Actions (High Priority)
- 🔧 Investigate and fix timer cancellation issues
- 🔧 Add proper synchronization for completer state management
Short-term Actions (Medium Priority)
- 🔧 Improve request body handling with better null checks
- 🔧 Create more specific exception types for better error handling
- 🔧 Add comprehensive URL parameter encoding validation
- 🔧 Add retry policy validation and limits
Long-term Actions (Low Priority)
- 🔧 Improve type safety in exception classes
- 🔧 Add case-insensitive HTTP method parsing
- 🔧 Enhance extension type safety
- 📝 Add comprehensive edge case tests
🎯 Success Criteria
For High Priority Issues
For Medium Priority Issues
For Low Priority Issues
📊 Issue Summary
| Priority |
Count |
Status |
| High |
2 |
1 Fixed, 1 Pending |
| Medium |
3 |
All Pending |
| Low |
4 |
All Pending |
| Testing |
1 |
Pending |
Total Issues: 10
Fixed: 1
Pending: 9
🔍 Monitoring
Areas to Monitor
- Memory usage patterns in long-running applications
- Exception frequency and types in production
- Performance impact of retry policies
- URL encoding edge cases in real-world usage
Metrics to Track
- Timer cancellation success rate
- Completer completion patterns
- Exception type distribution
- Retry attempt frequency
📚 References
Last Updated: [Current Date]
Status: Active Monitoring Required
Known Issues in http_interceptor
This document outlines the remaining issues found in the codebase that should be addressed for improved robustness and reliability.
🔧 Issues by Priority
High Priority Issues
1. Potential Memory Leak: Timer Not Always Cancelled
Location:⚠️ Needs Investigation
lib/http/intercepted_client.dartlines 340-348Status:
Issue: The timeout timer might not be cancelled in all code paths, potentially causing memory leaks.
Risk: If the completer is completed through the timeout callback, the timer might not be cancelled in all scenarios.
Suggested Fix: Ensure timer cancellation in all completion paths and add proper cleanup.
2. Race Condition: Completer State Management
Location:⚠️ Needs Investigation
lib/http/intercepted_client.dartlines 310-350Status:
Issue: Multiple code paths can complete the same completer, potentially causing race conditions.
Risk: Multiple threads or async operations could try to complete the same completer simultaneously.
Suggested Fix: Add proper synchronization or use atomic operations for completer state management.
Medium Priority Issues
3. Potential Null Reference: Request Body Handling
Location:
lib/http/intercepted_client.dartlines 240-251Status: 🔧 Needs Improvement
Issue: The body type checking doesn't handle all possible null cases properly.
Suggested Fix: Add null checks and better type validation.
4. Inconsistent Error Handling: StreamedResponse Type Check
Location:
lib/http/intercepted_client.dartlines 220-227Status: 🔧 Needs Improvement
Issue: The type check for StreamedResponse throws a generic ClientException instead of a more specific error.
Impact: This makes debugging harder as the error message doesn't provide enough context.
Suggested Fix: Create a more specific exception type or improve error messages.
5. Potential Issue: URL Parameter Encoding
Location:
lib/utils/query_parameters.dartlines 42-60Status: 🔧 Needs Investigation
Issue: The URL parameter encoding logic might not handle all edge cases properly.
Risk: If
value.toString()returns null or throws an exception, this could cause issues.Suggested Fix: Add proper null checks and exception handling.
Low Priority Issues
6. Potential Issue: Retry Policy State Management
Location:
lib/http/intercepted_client.dartlines 360-380Status: 🔧 Needs Improvement
Issue: The retry count is reset for each new request, but there's no validation that retry attempts don't exceed reasonable limits.
Risk: A malicious retry policy could cause infinite loops or excessive retries.
Suggested Fix: Add maximum retry limits and validation.
7. Minor Issue: Inconsistent Exception Types
Location:
lib/models/http_interceptor_exception.dartStatus: 🔧 Needs Improvement
Issue: The custom exception class uses
dynamicfor the message, which could lead to type safety issues.Suggested Fix: Change to
String?for better type safety.8. Potential Issue: Extension Type Safety
Location:
lib/extensions/base_request.dartlines 15-70Status: 🔧 Needs Improvement
Issue: The
copyWithmethod usesdynamicfor the body parameter, which could cause runtime errors.Suggested Fix: Use more specific types or add runtime type checking.
9. Minor Issue: Missing Validation in HTTP Methods
Location:
lib/http/http_methods.dartlines 15-29Status: 🔧 Needs Improvement
Issue: The
fromStringmethod doesn't handle case-insensitive parsing or trim whitespace.Suggested Fix: Add case-insensitive parsing and whitespace trimming.
🧪 Testing Issues
Test Coverage Gaps
10. Missing Edge Case Tests
Status: 📝 Needs Additional Tests
Areas needing more test coverage:
Suggested Action: Add comprehensive edge case tests for all identified issues.
📋 Action Items
Immediate Actions (High Priority)
Short-term Actions (Medium Priority)
Long-term Actions (Low Priority)
🎯 Success Criteria
For High Priority Issues
For Medium Priority Issues
For Low Priority Issues
📊 Issue Summary
Total Issues: 10
Fixed: 1
Pending: 9
🔍 Monitoring
Areas to Monitor
Metrics to Track
📚 References
Last Updated: [Current Date]
Status: Active Monitoring Required