You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "damccorm (via GitHub)" <gi...@apache.org> on 2025/02/24 19:22:27 UTC
[PR] Fix race condition [beam]
damccorm opened a new pull request, #34058:
URL: https://github.com/apache/beam/pull/34058
It seems that not all Datasources are thread safe when creating connections and can hang when many threads try to create connections at once. Since datasources can be shared across threads, this creates a problem. This pr attempts to resolve the problem, though right now I'm mostly using it to test/validate the fix.
Still TODO:
- [ ] Fix the other `getConnection` function if this works.
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2691065185
Launching some performance tests to see if this change has any impact: https://github.com/apache/beam/actions/runs/13592236722
I'm hopeful it won't since:
1) It should only be paid once per bundle
2) Actually reading/writing should be the dominant part of this workload, not getting a connection. If getting a connection is slow, that probably means that there just aren't enough connections to go around
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2691211274
Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment `assign set of reviewers`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2691202732
Assigning reviewers. If you would like to opt out of this review, comment `assign to next reviewer`:
R: @Abacn for label java.
R: @Abacn for label io.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "liferoad (via GitHub)" <gi...@apache.org>.
liferoad commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2692253152
Shall we call this out in CHANGES.md?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2691193885
Yeah, seems like little to no perf impact.
My [run with this change](https://github.com/apache/beam/actions/runs/13592236722/job/38000902912):

Previous 5 runs:
[run 1](https://github.com/apache/beam/actions/runs/13586064344):

[run 2](https://github.com/apache/beam/actions/runs/13576963293):

[run 3](https://github.com/apache/beam/actions/runs/13564068853):

[run 4](https://github.com/apache/beam/actions/runs/13554463358):

[run 5](https://github.com/apache/beam/actions/runs/13541591273):

My updated version actually did the best here on both metrics, so it seems like it should be pretty safe.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2691208779
R: @Abacn
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm merged PR #34058:
URL: https://github.com/apache/beam/pull/34058
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on code in PR #34058:
URL: https://github.com/apache/beam/pull/34058#discussion_r1976055385
##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java:
##########
@@ -1634,12 +1637,22 @@ public void setup() throws Exception {
}
private Connection getConnection() throws SQLException {
- Connection connection = this.connection;
- if (connection == null) {
- DataSource validSource = checkStateNotNull(this.dataSource);
- connection = checkStateNotNull(validSource).getConnection();
- this.connection = connection;
+ Connection connection;
+ DataSource validSource = checkStateNotNull(this.dataSource);
+ boolean reportLineage = false;
+ connectionLock.lock();
+ try {
+ connection = this.connection;
Review Comment:
Yeah, I think you're right that we can shrink the lock. I was worried about the case where `this.connection` gets set while waiting on the lock, but I don't think we need to worry about this as long as there's a 1:1 mapping of DoFn to thread.
I'll update
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on code in PR #34058:
URL: https://github.com/apache/beam/pull/34058#discussion_r1976067737
##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java:
##########
@@ -1634,12 +1637,22 @@ public void setup() throws Exception {
}
private Connection getConnection() throws SQLException {
- Connection connection = this.connection;
- if (connection == null) {
- DataSource validSource = checkStateNotNull(this.dataSource);
- connection = checkStateNotNull(validSource).getConnection();
- this.connection = connection;
+ Connection connection;
+ DataSource validSource = checkStateNotNull(this.dataSource);
+ boolean reportLineage = false;
+ connectionLock.lock();
+ try {
+ connection = this.connection;
Review Comment:
Done - thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "Abacn (via GitHub)" <gi...@apache.org>.
Abacn commented on code in PR #34058:
URL: https://github.com/apache/beam/pull/34058#discussion_r1976050617
##########
sdks/java/io/jdbc/src/main/java/org/apache/beam/sdk/io/jdbc/JdbcIO.java:
##########
@@ -1634,12 +1637,22 @@ public void setup() throws Exception {
}
private Connection getConnection() throws SQLException {
- Connection connection = this.connection;
- if (connection == null) {
- DataSource validSource = checkStateNotNull(this.dataSource);
- connection = checkStateNotNull(validSource).getConnection();
- this.connection = connection;
+ Connection connection;
+ DataSource validSource = checkStateNotNull(this.dataSource);
+ boolean reportLineage = false;
+ connectionLock.lock();
+ try {
+ connection = this.connection;
Review Comment:
I understand the race happened when creating connections. Is it necessary to put "connection = this.connection;" inside lock? This causes every getConnection() go through a lock (though tested it has little performance effect)
Or is it preferrable to only synchronize "connection = validSource.getConnection();" ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Fix race condition [beam]
Posted by "damccorm (via GitHub)" <gi...@apache.org>.
damccorm commented on PR #34058:
URL: https://github.com/apache/beam/pull/34058#issuecomment-2694419797
> Shall we call this out in CHANGES.md?
Sure, https://github.com/apache/beam/pull/34147
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org