Skip to content

Conversation

@jenfonro
Copy link
Contributor

@jenfonro jenfonro commented Nov 21, 2025

Description / 描述

当任务失败时,刷新缓存的headers,来防止过久的等待刷新

Motivation and Context / 背景

频繁报错%!w(<nil>); CreateTempFile failed, size mismatch: 570 != 10480

任务报错失败后,重试时大概率会出现同样的情况,

How Has This Been Tested? / 测试

Checklist / 检查清单

  • I have read the CONTRIBUTING document.
    我已阅读 CONTRIBUTING 文档。
  • I have formatted my code with go fmt or prettier.
    我已使用 go fmtprettier 格式化提交的代码。
  • I have added appropriate labels to this PR (or mentioned needed labels in the description if lacking permissions).
    我已为此 PR 添加了适当的标签(如无权限或需要的标签不存在,请在描述中说明,管理员将后续处理)。
  • I have requested review from relevant code authors using the "Request review" feature when applicable.
    我已在适当情况下使用"Request review"功能请求相关代码作者进行审查。
  • I have updated the repository accordingly (If it’s needed).
    我已相应更新了相关仓库(若适用)。

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves header refresh handling in the OneDrive sharelink driver to reduce temporary file errors caused by expired authentication headers. When download tasks fail, the code now proactively refreshes cached headers instead of waiting for the periodic refresh cycle.

Key changes:

  • Introduced thread-safe header management with sync.RWMutex and singleflight pattern to prevent concurrent refresh storms
  • Reduced header TTL from 30 minutes to 25 minutes and added automatic refresh logic in the Link() method
  • Added RangeReader with retry-on-failure logic that automatically refreshes headers when encountering invalid responses
Comments suppressed due to low confidence (7)

drivers/onedrive_sharelink/driver.go:1

  • Direct access to d.Headers without lock protection. This should use d.headerSnapshot() to avoid potential race conditions with concurrent header updates from the cron job or refresh operations.
package onedrive_sharelink

drivers/onedrive_sharelink/driver.go:1

  • Direct access to d.Headers without lock protection at lines 202 and 211. These accesses should use d.headerSnapshot() to prevent race conditions during concurrent header updates.
package onedrive_sharelink

drivers/onedrive_sharelink/driver.go:1

  • Direct access to d.Headers without lock protection at lines 202 and 211. These accesses should use d.headerSnapshot() to prevent race conditions during concurrent header updates.
package onedrive_sharelink

drivers/onedrive_sharelink/driver.go:1

  • Direct writes to d.Headers at lines 225, 302, 332, and 347 bypass the new thread-safe storeHeaders() method. These should be updated to use d.storeHeaders() or preferably replaced with calls to d.refreshHeaders(ctx) to ensure thread safety and consistency.
package onedrive_sharelink

drivers/onedrive_sharelink/driver.go:1

  • Direct writes to d.Headers at lines 225, 302, 332, and 347 bypass the new thread-safe storeHeaders() method. These should be updated to use d.storeHeaders() or preferably replaced with calls to d.refreshHeaders(ctx) to ensure thread safety and consistency.
package onedrive_sharelink

drivers/onedrive_sharelink/driver.go:1

  • Direct writes to d.Headers at lines 225, 302, 332, and 347 bypass the new thread-safe storeHeaders() method. These should be updated to use d.storeHeaders() or preferably replaced with calls to d.refreshHeaders(ctx) to ensure thread safety and consistency.
package onedrive_sharelink

drivers/onedrive_sharelink/driver.go:1

  • Direct writes to d.Headers at lines 225, 302, 332, and 347 bypass the new thread-safe storeHeaders() method. These should be updated to use d.storeHeaders() or preferably replaced with calls to d.refreshHeaders(ctx) to ensure thread safety and consistency.
package onedrive_sharelink

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@ILoveScratch2 ILoveScratch2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jenfonro jenfonro merged commit ede96a3 into OpenListTeam:main Nov 25, 2025
20 checks passed
@jenfonro jenfonro deleted the onedrive-share branch December 1, 2025 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement go Module: Driver Driver-Related Issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants