fix: correct LRU cache list operation from PushFront to MoveToFront#1808
Merged
MarksonHon merged 1 commit intov2rayA:mainfrom Jan 25, 2026
Merged
Conversation
问题描述:
- lru.go 的 get() 函数使用了 PushFront(v) 而不是 MoveToFront(v)
- 这导致 list.Element 被重复添加到列表中,破坏了列表结构
- 当缓存淘汰时,back.Value 可能指向 *list.Element 而不是 *EncapsulatedValue
- 类型断言失败:interface{} is *list.Element, not *lru.EncapsulatedValue
修复方法:
- 将 l.list.PushFront(v) 改为 l.list.MoveToFront(v)
- MoveToFront 会将现有 element 移到列表前面,而不是创建新的 element
Fixes: interface conversion error in LRU cache
YLinXin
pushed a commit
to YLinXin/v2rayA
that referenced
this pull request
Apr 5, 2026
…rsion-error fix: correct LRU cache list operation from PushFront to MoveToFront
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Bug Description
Type conversion error occurred when deploying v2rayA with Docker:
Environment
Stack Trace
🔍 Root Cause
In the
get()function at line 62 ofservice/infra/dataStructure/lru/lru.go, the wrong list operation method was used:Problematic code:
This causes:
list.Elementis duplicated in the list, corrupting the list structureback.Valuemay point to*list.Elementinstead of the expected*EncapsulatedValueback.Value.(*EncapsulatedValue)fails✅ Fix
Changed
PushFront(v)toMoveToFront(v):Key difference:
PushFront(v): Adds v as a value to the list, creating a new elementMoveToFront(v): Moves v (which must be an existing element) to the front of the list, without creating a new element📝 Testing
🔧 Impact
service/infra/dataStructure/lru/lru.go