Should `write` with an `END_TOKEN` call `finalize` on the stream to prevent memory leaks?
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- julia
- Ambito
- performance
Direzione di ricerca
Inizia con l'esempio TOKEN_END nella documentazione e con il codice del ciclo di vita dello stream in src/stream.jl intorno alle righe 174–183. Riproduci la perdita con lo snippet Julia, quindi confronta i comportamenti proposti di finalize, finalizer e closed-mode. Done deve preservare il buffer sottostante rilasciando al contempo in modo immediato le risorse dello stream di transcoding.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Julia
- Stelle
- 90
- Fork
- 26
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di JuliaIO/TranscodingStreams.jl
-
Allow generic `DenseVector{UInt8}` as input/outputForse già presa @nhz2 l’ha presa 460 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
JuliaIO/TranscodingStreams.jl#247 · 2 commenti ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
JuliaIO/TranscodingStreams.jl#246 · 1 commento ·
-
Support libaec?Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
JuliaIO/TranscodingStreams.jl#207 · 2 commenti ·
-
API for BufferAperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
JuliaIO/TranscodingStreams.jl#202 · 2 commenti · 1 reazione ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
JuliaIO/TranscodingStreams.jl#188 ·
Tutte le issue di JuliaIO/TranscodingStreams.jl
Issue simili
-
Overload == for ZGroupAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
question
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
brown-ccv/Chamber.jl#272 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
JuliaAstro/SolarPosition.jl#143 ·
-
distributions
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
JuliaBayes/Wren.jl#404 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
JuliaAI/MLJTransforms.jl#113 ·
I maintainer di solito rispondono entro 1 giorno