Closed marzhaev closed 3 years ago
Sorry, I didn't realise issues were disabled is it possible that the process is exiting before GC cleans up the objects?
GC seems to only clean up objects once the scope they were created in has disappeared https://github.com/crystal-lang/crystal/issues/10469
The issue was discovered in production and replicated in different ways. I don't believe it has got to do with crystal-lang/crystal#10469.
My fix for Crystal MongoDB driver could be found here. Scroll down to the very bottom to collection.cr. It may be tough to read the code, let me explain.
C binding inits 'reply' which is a C type and hence does not get GC-ed by Crystal automatically. If it were inside a Crystal type then we should have used Crystal's finalized to manually free memory.
The same may be happening with openssl_ext. Around line 20 we may be bypassing Crystal's GC and not freeing bio manually via LibCrypto.bio_free further down the code. Unfortunately, I have never been able to get acquainted with OpenSSL's API to dig further.
Great point! I can't imagine many people are too intimately acquainted with OpenSSL's API - I'll have a dig
sweet that is fixed in the v2.1.4 release
Valgrind points to a memory leak in a dependency library - spider-gazelle/openssl_ext
where my code is
Based on my experience, I believe to have narrowed it down to here. Unfortunately, I'm unqualified to deal with OpenSSL's BIO and spider-gazelle/openssl_ext repository has got Issues disabled.
I hope someone qualified enough will be here to help out.