Should `write` with an `END_TOKEN` call `finalize` on the stream to prevent memory leaks?
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- julia
- Lĩnh vực
- performance
Hướng nghiên cứu
Bắt đầu với ví dụ TOKEN_END trong tài liệu và mã vòng đời stream trong src/stream.jl, quanh các dòng 174–183. Tái hiện hiện tượng rò rỉ bằng đoạn mã Julia, sau đó so sánh các hành vi được đề xuất của finalize, finalizer và closed-mode. Done phải giữ lại buffer nền tảng đồng thời chủ động giải phóng các tài nguyên của transcoding stream.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
The desire here is to close the TranscodingStream without closing the underlying buffer. This is documented in https://juliaio.github.io/TranscodingStreams.jl/latest/examples/#Explicitly-finish-transcoding-by-writing-TOKEN_END-1 and says that you should write a TOKEN_END token to the stream. However, an issue with that is that it only flushes the stream but it doesn't finalize it which leads to memory leaks in code written like:
using CodecZlib
using TranscodingStreams
function leak()
buf = IOBuffer()
data = rand(10^6)
while true
zWriter = ZlibCompressorStream(buf)
write(zWriter, data)
write(zWriter, TranscodingStreams.TOKEN_END)
flush(zWriter)
end
end
leak()
which will indefinitely leak. Manually calling finalize on the zWriter fixes the issue but it is not clear from the documentation that this is required. There are a few possible solutions:
- Attach a finalizer to the stream that calls
finalize. This is not ideal because you want a more eager cleanup than whenever the GC gets to it. - Make writing a
TOKEN_ENDcallfinalizeon the stream. - Make writing a
TOKEN_ENDset the stream mode to:closedand thereby allowingcloseon the wrapper stream to not close the underlying wrapped stream : https://github.com/JuliaIO/TranscodingStreams.jl/blob/2fac97171c2ff7b6828f49e34c22eb929cb672a1/src/stream.jl#L174-L183
Alternatively, it is also possible that the code that shows the leak above is "faulty" but generally, normal Julia code shouldn't leak like this so at least a finalizer might be a good idea.
- Ngôn ngữ chính
- Julia
- Star
- 90
- Fork
- 26
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
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.
Issue khác của JuliaIO/TranscodingStreams.jl
-
Allow generic `DenseVector{UInt8}` as input/outputCó thể đã có người làm @nhz2 đã nhận 460 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
JuliaIO/TranscodingStreams.jl#247 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
JuliaIO/TranscodingStreams.jl#246 · 1 bình luận ·
-
Support libaec?Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
JuliaIO/TranscodingStreams.jl#207 · 2 bình luận ·
-
API for BufferĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
JuliaIO/TranscodingStreams.jl#202 · 2 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
JuliaIO/TranscodingStreams.jl#188 ·
Tất cả issue của JuliaIO/TranscodingStreams.jl
Issue tương tự
-
Overload == for ZGroupĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
-
question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
brown-ccv/Chamber.jl#272 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
JuliaAstro/SolarPosition.jl#143 ·
-
distributions
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
JuliaBayes/Wren.jl#404 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
JuliaAI/MLJTransforms.jl#113 ·
Maintainer thường phản hồi trong vòng 1 ngày