Should `write` with an `END_TOKEN` call `finalize` on the stream to prevent memory leaks?
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- julia
- 領域
- performance
調査の方向性
ドキュメントの TOKEN_END の例と、src/stream.jl の 174–183 行付近にあるストリームのライフサイクルコードから始めます。Julia スニペットでリークを再現し、その後、提案されている finalize、finalizer、closed-mode の動作を比較します。Done では、基盤となるバッファーを保持しながら、transcoding stream のリソースを直ちに解放する必要があります。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Julia
- スター
- 90
- フォーク
- 26
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
JuliaIO/TranscodingStreams.jl のほかの issue
-
Allow generic `DenseVector{UInt8}` as input/output対応中かも @nhz2 が 460 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
JuliaIO/TranscodingStreams.jl#247 · コメント 2 件 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
JuliaIO/TranscodingStreams.jl#246 · コメント 1 件 ·
-
Support libaec?オープン
難易度 3/5 1〜2日 初心者へのやさしさ 25/100
JuliaIO/TranscodingStreams.jl#207 · コメント 2 件 ·
-
API for Bufferオープン
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
JuliaIO/TranscodingStreams.jl#202 · コメント 2 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
JuliaIO/TranscodingStreams.jl#188 ·
JuliaIO/TranscodingStreams.jl の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
-
question
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
brown-ccv/Chamber.jl#272 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
JuliaAstro/SolarPosition.jl#143 ·
-
distributions
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
JuliaBayes/Wren.jl#404 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
JuliaAI/MLJTransforms.jl#113 ·
メンテナーはふだん 1 日以内に返信