Skip to content

[SPARK-60246][FOLLOWUP][CORE] Remove logging from FileDownloadCallback and test the close-during-write path - #59532

Closed
cravani wants to merge 3 commits into
apache:masterfrom
cravani:followup-spark-60246
Closed

cravani wants to merge 3 commits into
apache:masterfrom
cravani:followup-spark-60246

Conversation

@cravani

@cravani cravani commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Follow-up to #59472.

  • FileDownloadCallback no longer logs. Its callbacks run on the files-client event loop, and logging there can block on a class loader that is itself waiting on that event loop, for example ExecutorClassLoader fetching a class over the same connection (SPARK-38446). A class-level comment on FileDownloadCallback now states this rule for all of its callbacks. The discarding flag only existed to log once, so it is removed too.

  • The file download tests in NettyRpcEnvSuite set spark.files.io.numConnectionsPerPeer to 1, so the downloads in a test always share one connection. They are also prefixed with SPARK-60246: .

  • New test SPARK-60246: download callbacks drop data for a closed reader, report other failures, and do not log. It gets the real callbacks through a mocked download client and checks three cases:

    • When the reader closes while onData is blocked in the pipe write, onData returns without throwing, and later data for that stream is dropped.
    • When the sink fails while the reader is still open, onData throws ClosedChannelException, so a real write failure is not hidden as a truncated download.
    • When the stream fails, onFailure passes its exact error to the reader.

    It also checks that the callbacks log nothing.

Why are the changes needed?

#59472 added debug logs on the files-client event loop, which can deadlock as described above. Its early-close test closes the reader before data arrives, so it does not reliably reach the catch for a reader that closes during a write. No test covered the !source.isOpen() guard on that catch. The tests also relied on the default of one connection per peer.

Does this PR introduce any user-facing change?

No

How was this patch tested?

Ran the SPARK-60246 tests in NettyRpcEnvSuite, SslNettyRpcEnvSuite, and AutoNettyRpcEnvSuite. The new test fails if the catch guard in onData is narrowed to case _: IOException =>, if onFailure stops passing its error to the reader, or if a callback logs.

Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 5.5

@cravani
cravani force-pushed the followup-spark-60246 branch from cf5356f to c5d3295 Compare October 15, 2026 23:45
@uros-b

uros-b commented Oct 17, 2026

Copy link
Copy Markdown
Member

Thank you @cravani and @gengliangwang!

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the fix, @cravani. I reviewed the latest commit, c5d3295, and left 9 inline comments. Here is a summary, ordered by priority.

Logging on the event loop

  1. FileDownloadCallback L453: the no-logging rule only sits in onData, but onFailure is where SPARK-38446 removed the same kind of log. A class-level comment citing SPARK-38446 would cover all three callbacks.
  2. FileDownloadCallback L454: the root cause is that the files-client event loop can inherit an ExecutorClassLoader as its context class loader, and network-common still logs throwables on it. This could be fixed in downloadClient (L406) under a separate JIRA.

Tests

  1. FileDownloadCallback L461: no test covers the if !source.isOpen() guard, so dropping it would let real sink failures truncate downloads silently.
  2. NettyRpcEnvSuite L324: assert(!buf.hasRemaining) pins a detail that no caller relies on, and L325-327 only check that onData does not throw.
  3. NettyRpcEnvSuite L288: clientMode = true is enough, since the transport is mocked.
  4. NettyRpcEnvSuite L287: the new test, and the three from #59472, could use the SPARK-60246: prefix.

Cleanup

  1. NettyRpcEnvSuite L312-317: JavaUtils.readFully does the same.
  2. NettyRpcEnvSuite L296: optionally, private[netty] on the two classes would let the test build the callback directly.

PR description

  1. NettyRpcEnvSuite L290: "never reaches the catch" overstates, AutoNettyRpcEnvSuite is missing, and the AI section lacks the Generated-by: phrase.

Items 1 and 3 are the ones I'd like to see in this PR. Item 2 can be a follow-up JIRA, and the rest are nits. Since #59472 is also in branch-4.x, this follow-up should go there too; it applies cleanly.

@cravani

cravani commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, @dongjoon-hyun I've tried addressing 1 and 3 through 9 in the latest commit, will open a separate Jira for 2 once this is fixed.

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing items 1 and 3-9, @cravani. I reviewed the latest commit, c214a92, and left 4 inline comments. Here is a summary, ordered by priority, continuing the numbering from items 1-9.

Tests

  1. NettyRpcEnvSuite L342: the no-log check never calls onFailure, where SPARK-38446 removed the original log, so adding that log back would keep the test green.
  2. NettyRpcEnvSuite L346: source and otherSource are closed only on the success path, so a failed assertion leaves both pipes open.
  3. NettyRpcEnvSuite L348: the assertion counts every event on the NettyRpcEnv logger from any thread, including the suite's shared env, not only the callbacks.
  4. NettyRpcEnvSuite L323: the blocking write runs on ExecutionContext.global, which is never shut down and is not in ThreadAudit's allow-list.

Item 10 is the one I'd like to see in this PR, since it closes the gap that item 1 was about. The rest are nits.

@cravani

cravani commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

Thanks again @dongjoon-hyun for the review. I've updated changes on latest commit for 10-13. I also renamed the new test, since it now covers more than the close-during-write case.

@cravani
cravani requested a review from dongjoon-hyun October 20, 2026 23:58
@cravani

cravani commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

Hello @dongjoon-hyun I wanted to check if you had a chance to go by the latest change any feedbacks?

@dongjoon-hyun dongjoon-hyun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM.

gengliangwang pushed a commit that referenced this pull request Oct 23, 2026
…k and test the close-during-write path

### What changes were proposed in this pull request?
Follow-up to #59472.

- `FileDownloadCallback` no longer logs. Its callbacks run on the files-client event loop, and logging there can block on a class loader that is itself waiting on that event loop, for example `ExecutorClassLoader` fetching a class over the same connection (SPARK-38446). A class-level comment on `FileDownloadCallback` now states this rule for all of its callbacks. The `discarding` flag only existed to log once, so it is removed too.
- The file download tests in `NettyRpcEnvSuite` set `spark.files.io.numConnectionsPerPeer` to 1, so the downloads in a test always share one connection. They are also prefixed with `SPARK-60246: `.
- New test `SPARK-60246: download callbacks drop data for a closed reader, report other failures, and do not log`. It gets the real callbacks through a mocked download client and checks three cases:
  - When the reader closes while `onData` is blocked in the pipe write, `onData` returns without throwing, and later data for that stream is dropped.
  - When the sink fails while the reader is still open, `onData` throws `ClosedChannelException`, so a real write failure is not hidden as a truncated download.
  - When the stream fails, `onFailure` passes its exact error to the reader.

  It also checks that the callbacks log nothing.

### Why are the changes needed?
#59472 added debug logs on the files-client event loop, which can deadlock as described above. Its early-close test closes the reader before data arrives, so it does not reliably reach the `catch` for a reader that closes during a write. No test covered the `!source.isOpen()` guard on that `catch`. The tests also relied on the default of one connection per peer.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?
Ran the `SPARK-60246` tests in `NettyRpcEnvSuite`, `SslNettyRpcEnvSuite`, and `AutoNettyRpcEnvSuite`. The new test fails if the `catch` guard in `onData` is narrowed to `case _: IOException =>`, if `onFailure` stops passing its error to the reader, or if a callback logs.

### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5

Closes #59532 from cravani/followup-spark-60246.

Authored-by: Chiran Ravani <chiran54321@gmail.com>
Signed-off-by: Gengliang Wang <gengliang@apache.org>
(cherry picked from commit 415b032)
Signed-off-by: Gengliang Wang <gengliang@apache.org>
@gengliangwang

Copy link
Copy Markdown
Member

Merge Summary:

Posted by merge_spark_pr.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants