Skip to content

[FLINK-30371] Fix the problem of JdbcOutputFormat database connection leak #75

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

KevDi
Copy link

@KevDi KevDi commented Sep 24, 2023

I have redone the Fix from #5 because no more action is going on there.
I updated to the latest version of the main branch and also added the needed tests.
Hope this is fine so far.

@boring-cyborg
Copy link

boring-cyborg bot commented Sep 24, 2023

Thanks for opening this pull request! Please check out our contributing guidelines. (https://flink.apache.org/contributing/how-to-contribute.html)

@KevDi
Copy link
Author

KevDi commented Oct 19, 2023

Any news on that?

@KevDi KevDi changed the title [FLINK-30371][Connector/JDBC] Fix the problem of JdbcOutputFormat database connection leak [FLINK-30371] Fix the problem of JdbcOutputFormat database connection leak Oct 19, 2023
@eskabetxe
Copy link
Member

Hi @KevDi ,
Checks are not passing, please fix the commit message.
Thanks

@KevDi
Copy link
Author

KevDi commented Oct 27, 2023

Hi @eskabetxe is there a format that should be used for the Commits?

@eskabetxe
Copy link
Member

Should be on same format that you put on title of PT
[FLINK-XXXXX] Some text

And merge commits should be avoided..

Current you have 3 commit messages, the ideal is 1
image

The commit in the middle is ok, the other 2 no

@KevDi
Copy link
Author

KevDi commented Oct 27, 2023

Ok i try to compress the commits to one single commit :)

@KevDi
Copy link
Author

KevDi commented Oct 27, 2023

@eskabetxe had to experience a little bit but now it seems that only one commit is there =)

@eskabetxe
Copy link
Member

@MartijnVisser could you approve the workflow please

@KevDi
Copy link
Author

KevDi commented Nov 10, 2023

@eskabetxe @MartijnVisser i looked into this error but i was unable to resolve it. I removed the mentioned import with explicit imports but then i get an error telling me that some of the static imports are imported before others. If i used the Sort Imports´ on Intellij it removed the imports with the .*` version. Maybe i need some support with that.

@MartijnVisser
Copy link
Contributor

@KevDi You'll need to rebase, the Flink project doesn't do merge commits.

…Method.

This Problem leads to Connection Leaks if some problem occurs.
@KevDi
Copy link
Author

KevDi commented Nov 22, 2023

@MartijnVisser i have done the rebase.

@KevDi
Copy link
Author

KevDi commented Feb 15, 2024

@MartijnVisser any updates on this?

@fapaul
Copy link
Contributor

fapaul commented Feb 18, 2025

@EchoLee5 c @KevDi sorry for the long wait. Is anyone still willing to contribute this change? I can help with reviewing/merging this PR.

@lvyanquan
Copy link
Contributor

Hi, @KevDi.
Would you like to rebase and fix the conflict?

@KevDi
Copy link
Author

KevDi commented Feb 18, 2025

@fapaul i can try to take a look at it. Question would be if it is still enough to do the fix like i provided it here or if the solution from @tamirsagi here #5 (comment) would also work. I'm not sure about it because the error seems to come when the flush get an exception. It is then thrown upwords without a chance to close the connection.

@fapaul
Copy link
Contributor

fapaul commented Feb 20, 2025

@fapaul i can try to take a look at it. Question would be if it is still enough to do the fix like i provided it here or if the solution from @tamirsagi here #5 (comment) would also work. I'm not sure about it because the error seems to come when the flush get an exception. It is then thrown upwords without a chance to close the connection.

I prefer the solution via the autoclosable block because your current fix changes the semantics slightly. In case the flushException was previously set by the background executor we now overwrite it with this PR.

In general, can you maybe share a full stack trace or how you are using the JdbcOutputFormat? I am mainly interested in understanding which JdbcSink, in your case, calls the JdbcOutputFormat to make sure we do not miss a case.

@KevDi
Copy link
Author

KevDi commented Feb 20, 2025

@fapaul Ok i check if i found the old code. In general the question that i have is what happens if the flush call in close is throwing an exception. This will then been thrown upwards and from what i understand is that the connections are not closed at this point or am i wrong here?

@fapaul
Copy link
Contributor

fapaul commented Feb 21, 2025

You are correct that in case an error is thrown during calling close we might not clean up the database connection. That mostly affects jobs that have a restart strategy or jobs running on a session cluster e.g. the JVM is never shutdown.

To fully confirm your scenario that, it would be helpful to understand which JdbcSink you are using since the JdbcOutputFormat is usually not used directly by users.

@KevDi
Copy link
Author

KevDi commented Mar 3, 2025

@fapaul would it make sense to change both try-catch Blocks to try (connectionProvider) ? SO the one wrapping around the flush and the one wrapping around closeStatement call?

@fapaul
Copy link
Contributor

fapaul commented Mar 4, 2025

SO the one wrapping around the flush

I don't think that is necessary. The flush is either retried if configured or the exception fails the job, and eventually, closeStatement is invoked.

With the current architecture of different sink implementations all depending on the JdbcOutputFormat, I'd avoid any chances that change the behavior even more.

@KevDi
Copy link
Author

KevDi commented Mar 4, 2025

Ok but how should the connection leak beeing fixed then?

@fapaul
Copy link
Contributor

fapaul commented Mar 5, 2025

Sorry my previous message wasn't well-formatted (fixed now). The try-catch block around the closeStatement is ok, but I'd not touch the flush method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants