Skip to content

StreamPollFeeder: declare done and exception as volatile#387

Open
elharo wants to merge 3 commits into
masterfrom
fix/streampollfeeder-volatile
Open

StreamPollFeeder: declare done and exception as volatile#387
elharo wants to merge 3 commits into
masterfrom
fix/streampollfeeder-volatile

Conversation

@elharo

@elharo elharo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

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 volatileStreamPollFeeder should follow the same pattern.

Fixes #385
Fixes #386

@elharo elharo requested a review from kwin July 1, 2026 13:11
@slachiewicz slachiewicz added the bug Something isn't working label Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamPollFeeder.exception should be volatile StreamPollFeeder.done should be volatile (thread may hang)

2 participants