AbortSignal.any memory leak when circular dependencies
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- JavaScript
- Star
- 122k
- Fork
- 37.4k
- Merge trung bình
- 4 ngày 2 giờ
- Pull request đã merge (30 ngày)
- 283
Mô tả
Version
23.10.0
Platform
6.8.0-55-generic #57-Ubuntu SMP PREEMPT_DYNAMIC Wed Feb 12 23:42:21 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
class Test {
private abortController = new AbortController()
public test(cb: (abortSignal: AbortSignal) => void, abortSignal: AbortSignal) {
const signal = AbortSignal.any([abortSignal, this.abortController.signal])
cb(signal)
}
}
const registry = new FinalizationRegistry((heldValue) => {
console.log(`${heldValue} has been collected`)
})
;(() => {
const test = new Test()
registry.register(test, 'test')
const abortController = new AbortController()
test.test((abortSignal) => {
abortSignal.addEventListener('abort', () => {
console.log(test)
})
}, abortController.signal)
})()
global.gc?.()
setTimeout(() => {
console.log('the end')
}, 2000)
run with node --expose-gc test.ts
How often does it reproduce? Is there a required condition?
Every time
What is the expected behavior? Why is that the expected behavior?
the output should be
test has been collected
the end
because the test object is not referenced anymore
What do you see instead?
output:
the end
the test object is not garbage collected
Additional information
The issues seems to be caused by the cyclic dependency: test object => abortController field => abortSignal => AbortSignal.any result => cb function => test object
AbortSignal.any seems to prevent node from garbage collecting them all at once
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Chạy bản tái hiện được cung cấp với node --expose-gc và kiểm tra sự tương tác giữa AbortSignal.any, AbortController và FinalizationRegistry được mô tả trong issue. Hoàn thành khi đối tượng kiểm thử được thu gom và đầu ra bao gồm cả “test has been collected” và “the end”.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- javascript
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Sôi nổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100