Skip to content

Fix TCP timeout panic by implementing graceful error handling in Channels function#674

Merged
rabilrbl merged 2 commits into
developfrom
copilot/fix-667
Sep 21, 2025
Merged

Fix TCP timeout panic by implementing graceful error handling in Channels function#674
rabilrbl merged 2 commits into
developfrom
copilot/fix-667

Conversation

Copilot AI commented Sep 21, 2025

Copy link
Copy Markdown
Contributor

The application was crashing with a panic when network errors (including TCP timeouts) occurred while fetching channels from the JioTV API. This issue manifested when the television.Channels() function encountered network connectivity problems, causing the entire server to terminate unexpectedly.

Root Cause

The Channels() function in pkg/television/television.go was using utils.Log.Panic(err) to handle network errors, which terminated the entire application instead of gracefully handling the error condition.

Solution

This PR implements proper error handling by:

  1. Modified the Channels() function signature from func Channels() ChannelsResponse to func Channels() (ChannelsResponse, error) to allow error propagation
  2. Replaced panic calls with proper error logging using utils.Log.Printf() and returning the error to the caller
  3. Updated HTTP handlers (IndexHandler and ChannelsHandler) to handle the returned errors gracefully and respond with appropriate HTTP 500 error messages

Before (Problematic Behavior)

// Network error would cause application crash
resp, err := utils.MakeHTTPRequest(config, client)
if err != nil {
    utils.Log.Panic(err)  // 💥 Application terminates
}

After (Graceful Error Handling)

// Network error is handled gracefully
resp, err := utils.MakeHTTPRequest(config, client)
if err != nil {
    utils.Log.Printf("Error fetching channels from JioTV API: %v", err)
    return ChannelsResponse{}, err  // ✅ Error returned to caller
}

Benefits

  • Server stability: Network errors no longer crash the entire application
  • Better user experience: Clients receive proper HTTP 500 error responses with meaningful error messages instead of connection drops
  • Improved debugging: Errors are logged for troubleshooting while maintaining server operation
  • Minimal impact: Only essential changes made to core functionality

Testing

  • All existing tests continue to pass
  • Server remains responsive after multiple consecutive network failures
  • Error logging works correctly in debug mode
  • Proper HTTP error responses are returned to clients

Fixes #667.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/JioTV-Go/jiotv_go/releases/latest
    • Triggering command: ./build/jiotv_go serve --help (http block)
    • Triggering command: ./build/jiotv_go serve --host 127.0.0.1 --port 5001 (http block)
  • jiotvapi.cdn.jio.com
    • Triggering command: /tmp/go-build1136633696/b303/handlers.test -test.testlogfile=/tmp/go-build1136633696/b303/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build3291922151/b303/handlers.test -test.testlogfile=/tmp/go-build3291922151/b303/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: ./build/jiotv_go serve --host 127.0.0.1 --port 5001 (dns block)
  • jiotvapi.media.jio.com
    • Triggering command: /tmp/go-build1136633696/b284/cmd.test -test.testlogfile=/tmp/go-build1136633696/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build3291922151/b284/cmd.test -test.testlogfile=/tmp/go-build3291922151/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…nels function

Co-authored-by: rabilrbl <63334479+rabilrbl@users.noreply.github.com>
Copilot AI changed the title [WIP] bug: dialing to the given TCP address timed out Fix TCP timeout panic by implementing graceful error handling in Channels function Sep 21, 2025
Copilot AI requested a review from rabilrbl September 21, 2025 07:06
@rabilrbl rabilrbl marked this pull request as ready for review September 21, 2025 11:26
@rabilrbl rabilrbl merged commit c0a61e8 into develop Sep 21, 2025
12 checks passed
@rabilrbl rabilrbl deleted the copilot/fix-667 branch September 21, 2025 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: dialing to the given TCP address timed out

2 participants