Skip to content

get_codeforces_submission_stats has no timeout and crashes on malformed API responses #208

@amaydixit11

Description

@amaydixit11

Bug Description

The get_codeforces_submission_stats method and get_leetcode_data make external API calls with no timeout and no error handling, causing the entire endpoint to crash on network failures.

Affected Code

# views.py, line 259 - NO TIMEOUT
url = f"https://codeforces.com/api/user.status?handle={username}"
response = requests.get(url)  # Will hang forever if server doesn't respond
# views.py, line 463-464 - NO TIMEOUT, NO ERROR HANDLING
url = f"https://alfa-leetcode-api.onrender.com/userProfile/{username}"
response = requests.get(url)

if response.status_code == 200:
    data = response.json()  # If not 200, returns None implicitly

Impact

  • If Codeforces API hangs, the page never loads (no timeout set)
  • If LeetCode API returns 500/503, get_leetcode_data() returns None, causing KeyError when the caller does user_data["ranking"]
  • The onrender.com LeetCode proxy is on a free tier and frequently sleeps

Expected Behavior

  • All requests.get() calls should use timeout=30 to prevent hanging
  • The LeetCode endpoint should check if user_data is None before returning

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendDjango backend related tasksbugbug d73a4a 'Something isn't working'

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions