HDDS-15480. Potential for NPE / infinite loop in StreamBlockReader#10431
Conversation
|
This PR has been marked as stale due to 21 days of inactivity. Please comment or remove the stale label to keep it open. Otherwise, it will be automatically closed in 7 days. |
Conflicts: hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
…orage/TestStreamBlockInputStream.java
There was a problem hiding this comment.
Pull request overview
This PR fixes end-of-stream handling in StreamBlockInputStream’s streaming reader to prevent a NullPointerException on normal stream completion and to avoid an infinite loop when a response is fully skipped (eg after seek due to checksum-boundary alignment). It also adds unit tests that reproduce both the “fully-skipped first response” scenario and an EOF edge case where the stream completes before covering the seek position.
Changes:
- Handle
poll()/readFromQueue()returningnullas EOF instead of dereferencing and throwing NPE. - Ensure the internal
read()loop exits on stream end and continues fetching new responses when the current buffer is empty after skip. - Add unit tests covering checksum-aligned preamble skipping after seek and graceful EOF on premature stream completion.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
hadoop-hdds/client/src/main/java/org/apache/hadoop/hdds/scm/storage/StreamBlockInputStream.java |
Prevents NPE on stream completion and avoids infinite looping when skipped responses yield empty buffers. |
hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java |
Adds regression tests for checksum-alignment skip behavior and EOF handling when the stream completes early. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Merged. Thanks @sodonnel |
What changes were proposed in this pull request?
There is potential for an NPE at stream shutdown in the StreamBlockReader:
poll() explicitly returns null when future.isDone() is true (stream completed). However readFromQueue() uses the return value without a null check:
This fires in the normal shutdown path: after the server sends the last chunk and closes the stream, the next poll() call returns null and this line throws NullPointerException instead of letting the caller handle EOF gracefully.
Fixing this, can then cause an infinite loop in StreamingReader.read() (lines 446-451)
The inner read loop has no exit when readFromQueue() returns null or an empty buffer:
This could happen when:
Note - this builds on #10430 and will need rebased after it goes in.doneWhat is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-15480
How was this patch tested?
Unit tests added to reproduce the problem and ensure the fix corrects them.