@@ -43,6 +43,13 @@ func IsLinkExpiredError(err error) bool {
4343 if err == nil {
4444 return false
4545 }
46+
47+ // Don't treat context cancellation as link expiration
48+ // This happens when user pauses/seeks video or cancels download
49+ if errors .Is (err , context .Canceled ) || errors .Is (err , context .DeadlineExceeded ) {
50+ return false
51+ }
52+
4653 errStr := strings .ToLower (err .Error ())
4754
4855 // Common expired link error keywords
@@ -62,8 +69,8 @@ func IsLinkExpiredError(err error) bool {
6269 if statusErr , ok := errs .UnwrapOrSelf (err ).(net.HttpStatusCodeError ); ok {
6370 code := int (statusErr )
6471 // 401 Unauthorized, 403 Forbidden, 410 Gone are common for expired links
65- // 500 Internal Server Error - some providers (e.g., Baidu) return 500 when link expires
66- if code == 401 || code == 403 || code == 410 || code == 500 {
72+ // Note: Removed 500 to avoid false positives from temporary network errors
73+ if code == 401 || code == 403 || code == 410 {
6774 return true
6875 }
6976 }
@@ -158,7 +165,9 @@ func (r *RefreshableRangeReader) doRefreshLocked(ctx context.Context) error {
158165 }
159166
160167 log .Infof ("Link expired, attempting to refresh..." )
161- newLink , _ , refreshErr := r .link .Refresher (ctx )
168+ // Use independent context for refresh to prevent cancellation from affecting link refresh
169+ refreshCtx := context .WithoutCancel (ctx )
170+ newLink , _ , refreshErr := r .link .Refresher (refreshCtx )
162171 if refreshErr != nil {
163172 return fmt .Errorf ("failed to refresh link: %w" , refreshErr )
164173 }
0 commit comments