You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "sjvanrossum (via GitHub)" <gi...@apache.org> on 2026/07/30 06:32:15 UTC
[PR] Fix TSAN bug by swapping ForkJoinPool with ScheduledExecutorService [beam]
sjvanrossum opened a new pull request, #39556:
URL: https://github.com/apache/beam/pull/39556
This fixes the same issue as #39458 by having the `ScheduledExecutorService` establish a happens-before relationship between the submitting thread and executing thread, which appears to be missing for the common `ForkJoinPool` executor used by `MoreFutures.runAsync(ThrowingRunnable)` based on testing `TFRecordSchemaTransformProviderTest` with TSAN enabled. TSAN reports data races between the processing thread's write(s) to the `Writer` and the background thread's closing and/or cleanup of the `Writer` in [`CRC32`](https://docs.oracle.com/javase/8/docs/api/java/util/zip/CRC32.html) calls made by a gzip compressor.
`Writer` can be patched to establish acquire/release barriers between open and close/cleanup (e.g., by marking `channel` as `volatile` and adjusting reads/writes accordingly), but since `write` is `abstract` and the underlying `WritableByteChannel` is passed to implementations in `prepareWrite` instead of being accessed through its member field on the super class there's no point between any call to `write` and `close` which would insert the required memory barriers.
I can't think of any other tricks to make `Writer` inherently thread safe without modifying its public API as is already proposed in #39458. It is thread compatible at least, so it just needs external synchronization to play nice. Replacing the common `ForkJoinPool` with the harness `ScheduledExecutorService` as the executor for closing writers should be enough to take care of that.
------------------------
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 TSAN bug by swapping ForkJoinPool with ScheduledExecutorService [beam]
Posted by "sjvanrossum (via GitHub)" <gi...@apache.org>.
sjvanrossum commented on PR #39556:
URL: https://github.com/apache/beam/pull/39556#issuecomment-5130227034
@stankiewicz this looks like a false positive.
This test passes, but TSAN observes a stale read.
```java
package forkjoinpooltsantest;
import static com.google.common.truth.Truth.assertWithMessage;
import java.util.concurrent.ForkJoinPool;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class ForkJoinPoolMemoryTest {
private static final int STRESS_ITERATIONS = 100_000;
private static final Object EXPECTED = new Object();
/** Helper object containing plain (non-volatile) fields. */
private static final class Holder {
Object o;
}
@Test
public void testCommonPoolSubmit_plainWriteIsAlwaysVisible() {
for (int i = 0; i < STRESS_ITERATIONS; ++i) {
final Holder holder = new Holder();
holder.o = EXPECTED;
// Submit a task to the common pool to read the value of the plain field, then join and
// observe the returned value.
Object observed = ForkJoinPool.commonPool().submit(() -> holder.o).join();
assertWithMessage("Iteration %s: reference mismatch (possible stale read)", i)
.that(observed)
.isEqualTo(EXPECTED);
}
}
}
```
--
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 TSAN bug by swapping ForkJoinPool with ScheduledExecutorService [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39556:
URL: https://github.com/apache/beam/pull/39556#issuecomment-5128964569
Assigning reviewers:
R: @Abacn for label java.
Note: If you would like to opt out of this review, comment `assign to next reviewer`.
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 TSAN bug by swapping ForkJoinPool with ScheduledExecutorService [beam]
Posted by "sjvanrossum (via GitHub)" <gi...@apache.org>.
sjvanrossum commented on PR #39556:
URL: https://github.com/apache/beam/pull/39556#issuecomment-5128323808
I just came across [JDK-8386468](https://bugs.openjdk.org/browse/JDK-8386468), checking if that might have anything to do with TSAN's observations.
--
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 TSAN bug by swapping ForkJoinPool with ScheduledExecutorService [beam]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #39556:
URL: https://github.com/apache/beam/pull/39556#issuecomment-5127407439
> [!CAUTION]
> The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.
--
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 TSAN bug by swapping ForkJoinPool with ScheduledExecutorService [beam]
Posted by "sjvanrossum (via GitHub)" <gi...@apache.org>.
sjvanrossum closed pull request #39556: Fix TSAN bug by swapping ForkJoinPool with ScheduledExecutorService
URL: https://github.com/apache/beam/pull/39556
--
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