Skip to content
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

Make sure we close the connection and don't leak it in java sources. #10128

Closed
Tracked by #10386
tuliren opened this issue Feb 5, 2022 · 2 comments · Fixed by #20888
Closed
Tracked by #10386

Make sure we close the connection and don't leak it in java sources. #10128

tuliren opened this issue Feb 5, 2022 · 2 comments · Fixed by #20888

Comments

@tuliren
Copy link
Contributor

tuliren commented Feb 5, 2022

Summary

  • There seems to be connection leaks in some of the database connector.
  • We should verify this by adding a leak detection in acceptance test, and fix them.

Description

While investigating #9744, I found two phenomena:

  1. When a Redshift table is empty, reading it in a streaming does not seem to ever reach the onClose method of the stream, which is supposed to close the connection and now it is not executed, leaving the connection open.
  2. The StreamingJdbcDatabase may have connection leak. It calls getConnection from the data source, and it is left for the user to close those connection. When the 1) issue happens, the connection won't get closed.

Update

The issue is not from Redshift when the table is empty. It is connection leak. A Java Stream is not automatically closed. The onClose callback won't be triggered unless the Stream is manually closed. Many of the JdbcDatabase methods return a Stream, which needs to be manually closed or put in a try block. It is not always the case currently, resulting in connection leaks.

Reference

@grishick
Copy link
Contributor

grishick commented Jul 14, 2022

Support has been reporting issues with JDBC connectors during connection set up that may point to connection leaks as described in this blog post: https://mkyong.com/jdbc/hikaripool-1-connection-is-not-available-request-timed-out-after-30002ms/

@grishick grishick added the team/db-dw-sources Backlog for Database and Data Warehouse Sources team label Sep 27, 2022
@bleonard bleonard changed the title Detect JDBC connection leaks in database acceptance test Detect JDBC connection leaks in database acceptance test (and fix) Dec 14, 2022
@bleonard
Copy link
Contributor

bleonard commented Dec 14, 2022

let's catch exceptions and close the stream if it's still open.
ideally, we can come up with a test to prevent regressions.
try with resources?

@bleonard bleonard changed the title Detect JDBC connection leaks in database acceptance test (and fix) Make sure we close the connection and don't leak it in java sources. Dec 14, 2022
@VitaliiMaltsev VitaliiMaltsev linked a pull request Jan 22, 2023 that will close this issue
37 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants