-
Notifications
You must be signed in to change notification settings - Fork 76
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
Streaming with Akka-Anorm generates a materialized value as Future
that may never complete
#545
Comments
gaeljw
changed the title
Streaming with Akka-Anorm generates a materialized value as
Streaming with Akka-Anorm generates a materialized value as Apr 26, 2023
Future
that may never completesFuture
that may never complete
Adding that a "workaround" is to use a ...
.watchTermination()((_, done) => {
done.onComplete {
case Success(_) =>
connection.close()
case Failure(ex) =>
connection.close()
}
NotUsed // Or something else
}) But, if I understand correctly, this means that connection would be kept open until completion of the stream even if the SQL query itself doesn't need it anymore. This could be non desirable depending on downstream steps of the stream. |
cchantep
added a commit
to cchantep/anorm
that referenced
this issue
Apr 27, 2023
cchantep
added a commit
to cchantep/anorm
that referenced
this issue
Apr 27, 2023
cchantep
added a commit
to cchantep/anorm
that referenced
this issue
Apr 27, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Anorm Version (2.5.x / etc)
2.7.0
Operating System (Ubuntu 15.10 / MacOS 10.10 / Windows 10)
Linux ... 6.2.9-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Mar 30 22:31:57 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
JDK (Oracle 1.8.0_72, OpenJDK 1.8.x, Azul Zing)
Library Dependencies
Not relevant
Actual vs. Expected Behavior
We're using Anorm with Akka to stream long-running SQL queries results.
To do so, we have to manage the
Connection
manually (open and close it when appropriate). Our initial implementation used the materialized value of Akka-Anorm to close connection like this:However, we noticed that the
rowsRead
materialized value above never completes if the consumer of the stream close it while the SQL query is still running and pulling data.This leads to connection not closed and exhaustion of connection pool when using one.
More generally, the actual issue is that the materialized value may never complete.
Reproducible Test Case
I do have one in my project but I need to make it more minimal before sharing. I will update the issue if you feel it's needed.
The general idea to reproduce is to do something like this:
Possible explanation
Looking at the source code, I believe it's because the materialized value is managed through a
Promise
(https://github.com/playframework/anorm/blob/main/akka/src/main/scala/anorm/AkkaStream.scala#L122) which may never complete like in the case described above which I believe would trigger theonDownstreamFinish
method (https://github.com/playframework/anorm/blob/main/akka/src/main/scala/anorm/AkkaStream.scala#L182).The text was updated successfully, but these errors were encountered: