Skip to content

[flink][client] Close writer immediately on sink failover - #3817

Open
naivedogger wants to merge 1 commit into
apache:mainfrom
naivedogger:fix/sink-immediate-close
Open

[flink][client] Close writer immediately on sink failover#3817
naivedogger wants to merge 1 commit into
apache:mainfrom
naivedogger:fix/sink-immediate-close

Conversation

@naivedogger

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: close #3809

The Flink sink closed the client via Connection.close(), which closes the underlying WriterClient with an unbounded timeout. With pending records that cannot be sent (e.g. cluster unavailable during failover, with infinite writer retries by default), the sender's drain loop never exits and the task blocks in close, preventing failover from proceeding.

Brief change log

  • Connection: add a timeout-based close(Duration) API (default method, delegating to close()); zero/negative timeout means immediate close, abandoning unsent and in-flight requests.
  • FlussConnection: implement close(Duration); the no-arg close() keeps the previous graceful semantics (unbounded timeout).
  • WriterClient#close(Duration): a non-positive timeout now force-closes the sender up front instead of initiating a graceful close; when a graceful close times out, force-close the sender before interrupting the io thread, and bound the final wait (5s safety net) instead of reusing the caller timeout.
  • FlinkSinkWriter#close: close the connection with Duration.ZERO. Data correctness is unaffected: records are flushed on checkpoints, and on failover/cancellation un-flushed records are replayed from the last checkpoint. This mirrors Kafka's FlinkKafkaInternalProducer#close().

Tests

  • FlinkSinkWriterTest#testCloseReturnsPromptlyWhenFlussUnavailable: reproduces the failover scenario (cluster down + pending record + default infinite retries) and asserts close returns promptly. Verified it hangs and fails without the fix.
  • Existing FlinkSinkWriterTest tests still pass, including testCloseExceptionWhenFlussUnavailable (close still surfaces async write errors).

API and Format

Adds Connection#close(Duration) as a default method on the @PublicEvolving interface; existing implementations and callers are unaffected. No storage format changes.

Documentation

No documentation changes.

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.

[flink] Close writer immediately on sink failover

1 participant