You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2026/07/01 12:42:53 UTC
[PR] StreamPollFeeder: declare done and exception as volatile [maven-shared-utils]
elharo opened a new pull request, #387:
URL: https://github.com/apache/maven-shared-utils/pull/387
`StreamPollFeeder.done` and `StreamPollFeeder.exception` are accessed from multiple threads without `volatile`, violating the Java Memory Model.
**`done`** (line 40): read in `run()` outside any `synchronized` block (line 61), written in `waitUntilDone()` inside `synchronized (lock)` (line 107). When the feeder thread is continuously reading data (`input.available() > 0`), it never enters the `synchronized` block, so no happens‑before guarantees the write to `done` is ever seen. The thread loops forever and `waitUntilDone()`'s `join()` call hangs.
**`exception`** (line 38): written by the `run()` thread (lines 79, 92) and read from other threads via `getException()` (line 101). Without `volatile`, a thread calling `getException()` may see a stale `null`. `StreamPumper` already declares its equivalent field as `volatile` — `StreamPollFeeder` should follow the same pattern.
Fixes https://github.com/apache/maven-shared-utils/issues/385
Fixes https://github.com/apache/maven-shared-utils/issues/386
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StreamPollFeeder: declare done and exception as volatile [maven-shared-utils]
Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo merged PR #387:
URL: https://github.com/apache/maven-shared-utils/pull/387
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] StreamPollFeeder: declare done and exception as volatile [maven-shared-utils]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #387:
URL: https://github.com/apache/maven-shared-utils/pull/387#discussion_r3644895177
##########
src/test/java/org/apache/maven/shared/utils/cli/StreamPollFeederTest.java:
##########
@@ -20,14 +20,43 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.time.Duration;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
public class StreamPollFeederTest {
+ @Test
+ public void waitUntilFeederDoneWithContinuousData() {
+ // Simulates a stream with continuous data where the feeder thread
+ // never enters the synchronized(lock) wait block, so the done
+ // flag must be visible without relying on lock's happens-before.
+ InputStream continuousInput = new InputStream() {
+ @Override
+ public int available() {
+ return 1;
+ }
+
+ @Override
+ public int read() throws IOException {
+ return 0;
+ }
+ };
+
+ assertTimeoutPreemptively(Duration.ofSeconds(5), () -> {
+ StreamPollFeeder feeder = new StreamPollFeeder(continuousInput, new ByteArrayOutputStream());
+ feeder.start();
+ feeder.waitUntilDone();
+ assertNull(feeder.getException());
Review Comment:
This timeout-preemptive test can still leave a runaway non-daemon `StreamPollFeeder` thread running if the bug ever regresses (JUnit cancels the lambda thread, but does not stop spawned threads). Also, using `ByteArrayOutputStream` here risks unbounded heap growth if the feeder keeps writing. Consider using a discard `OutputStream` and mark the feeder thread as daemon to keep the test suite from hanging/OOMing on failure.
--
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: issues-unsubscribe@maven.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org