Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Race Condition: Incorrect AbortController Status Check During Tab Visibility Changes #95

Open
yushihang opened this issue Mar 11, 2025 · 0 comments · May be fixed by #94
Open

Race Condition: Incorrect AbortController Status Check During Tab Visibility Changes #95

yushihang opened this issue Mar 11, 2025 · 0 comments · May be fixed by #94

Comments

@yushihang
Copy link

yushihang commented Mar 11, 2025

Title: Race Condition: Incorrect AbortController Status Check During Tab Visibility Changes

Description

Bug Report

When rapidly switching browser tabs with openWhenHidden: false, the error handling logic incorrectly checks the abort status of a new request instead of the aborted one, leading to unnecessary retries.

Steps to Reproduce

  1. Create an EventSource connection with openWhenHidden: false
  2. Quickly switch to another tab and back
  3. Observe the network requests in DevTools

Current Behavior

  1. Initial request (A) starts with AbortController instance A
  2. Tab becomes hidden -> Controller A's abort() is called
  3. Tab becomes visible -> New request (B) starts with Controller B
  4. Request A's error handler executes but checks Controller B's status
  5. Since Controller B is not aborted, it triggers unnecessary retry

Expected Behavior

The error handler should check the abort status of the controller that initiated the request, not the current global controller instance.

Technical Details

The issue occurs because:

  • curRequestController is shared across async contexts
  • Error handling happens asynchronously after the controller reference has changed
  • This leads to checking the wrong controller's abort status

Impact

  • Unnecessary network requests
  • Incorrect error handling
  • Potential performance issues with rapid tab switching

Environment

  • Browser: All major browsers
  • Package Version: v2.0.1 (Latest version)
  • OS: All platforms

Suggested Fix

Store the AbortController instance in function scope to ensure error handling uses the correct instance for status checking.

Pull Request

#94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant