-
Notifications
You must be signed in to change notification settings - Fork 697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ResultSet & Statement leaks in simple query #871
Comments
What exposed version do you use? Could you prepare a sample project to check the memory leak? |
I'm not sure how to reproduce it, but I can confirm that PG-JDBC is complaining that there are leaks.
|
@MrPowerGamerBR , do you use Spring/SptingBoot or pure Exposed |
@Tapac pure Exposed transation, not using suspended queries. |
I don't know where it is, but all things point to there being a race between GC and resource releasing, such that under load a stop the world GC pause runs before the ByteBuf.release(). It's not a deterministic behavior, and I'm unable to trigger without doing a continual read. This seems to prove out with these two examples below. Note: The only change is to move the The only reason this isn't a problem for the standard Postgres Driver is they don't support binary streaming, so they just use
|
Maybe you are right and memory leak cause is not closed Blobs' InputStreams. |
We really appreciate you looking at this. I'm using 0.17.7 of Exposed for these code snippets by the way. I'm not convinced the issue is necessarily with Exposed or Impossbli's driver or Netty, but instead an unfortunate combination of the three in use.
If I'm understanding you right and you are saying maybe the leak is from not closing Blobs' InputStreams, I'm quite sure that's not the case. In fact (anecdotal of course) one of my coworker's switched temporarily to BlobColumnType because it bypasses this bug with the following. Note for Postgres blobAsStream is always true so the top if is always taken. While the else branch is never hit in our case it does appear to be missing a
The following is Impossibli's
Using BinaryColumnType, which doesn't have it's own
In Impossibli's driver, this results in it returning a default of the following based off the postgres column type. Return class type wasn't specified in the above This snippet is from Impossibli and is the default return type class for
The end result is BinaryColumnType and any classes that extend it in a setup which uses Postgres with Impossibli's driver, will have memory leaks if they aren't aware of the odd lifecycle requirements needed for binaryStreams in this setup. The This is not an important issue to our company because we don't have any need for binary streaming, but I'd expect if there is somehow a use case from some longer running binary stream, this would leak and bring down an app. |
The
PreparedStatement
allocated here:Exposed/exposed-jdbc/src/main/kotlin/org/jetbrains/exposed/sql/statements/jdbc/JdbcConnectionImpl.kt
Line 58 in fa61743
and the
ResultSet
allocated here:Exposed/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Query.kt
Line 80 in fa61743
are leaked because
close
is never called. Callingclose
is a requirement of JDBC and some drivers (e.g.pgjdbc-ng
) rely on this resource cleanup to keep memory usage optimized.I was using the smallest of tests while debugging an issue logged against the
pgjdbc-ng
driver so I cannot say this is the extent of the leaks; looking through the codebase it appears there may be quite a few more leaks similar to these.Here was my simple test:
FYI, I ran with the
pgjdbc-ng
driver and-Xmx256m
to help force GC which triggers the driver's internal leak housekeeper to report leaks.The text was updated successfully, but these errors were encountered: