Skip to content

[fix][tableview] Fix watchReaderForNewMessages to exit silently on normal shutdown and skip nil messages on error - #1557

Merged
crossoverJie merged 3 commits into
apache:masterfrom
zjxxzjwang:master-fix3
Nov 3, 2026
Merged

crossoverJie merged 3 commits into
apache:masterfrom
zjxxzjwang:master-fix3

Conversation

@zjxxzjwang

Copy link
Copy Markdown
Contributor

Motivation

When a TableView is closed, Close() calls reader.Close() which causes reader.Next() to return a ConsumerClosed error. However, the existing watchReaderForNewMessages had two problems:

  1. Error log on normal shutdown: The error check (ConsumerClosed / context.Canceled) was placed after the Errorf call, so every normal close would emit a spurious error log before the goroutine exited.

  2. Nil message passed to handleMessage on error: When reader.Next() returned a non-fatal error, the code fell through to handleMessage(msg) with a potentially nil message. Although a msg != nil guard existed, the lack of continue meant the control flow was fragile and confusing.

Modifications

  • Moved the ConsumerClosed / context.Canceled exit check inside the err != nil block, before the error log, so the goroutine exits silently on normal shutdown without logging.
  • Added continue after logging non-fatal errors to skip message handling entirely when msg may be nil.
  • Added inline comments explaining the two branches (normal shutdown vs. transient error).
  • Added three unit tests using a mockReader to verify:
    • TestWatchReaderExitsOnConsumerClosed — exits immediately on ConsumerClosed.
    • TestWatchReaderExitsOnContextCanceled — exits immediately on context cancellation.
    • TestWatchReaderRecoversFromTransientError — survives a transient error, delivers the next valid message, then exits on ConsumerClosed.

Verifying this change

This change added tests and can be verified as follows:

  • Added TestWatchReaderExitsOnConsumerClosed to verify the goroutine exits without further Next calls when ConsumerClosed is returned.
  • Added TestWatchReaderExitsOnContextCanceled to verify the goroutine exits when the context is cancelled.
  • Added TestWatchReaderRecoversFromTransientError to verify the loop continues after a transient error, processes a subsequent valid message, and finally exits on ConsumerClosed.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): no
  • The public API: no
  • The schema: no
  • The default values of configurations: no
  • The wire protocol: no

Documentation

  • Does this pull request introduce a new feature? no
  • If yes, how is the feature documented? not applicable
  • If a feature is not applicable for documentation, explain why? This is a bug fix for internal error handling logic with no user-facing API change.

…rmal shutdown and skip nil messages on error
@zjxxzjwang

Copy link
Copy Markdown
Contributor Author

@crossoverJie Hello, can you help me review this PR

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The regression tests need assertions for silent shutdown and actual message processing after a transient error.

2 open issues
What changed in this PR

This PR improves the TableView reader loop’s error handling so normal shutdown is silent and failed reads skip message processing.

Changes:

  • Exit before logging when the reader closes or the context is canceled.
  • Continue to the next read after logging other errors.
  • Add mock-based tests for shutdown and recovery after transient errors.
File Description
pulsar/​table_view_test.go Adds reader and message mocks plus three watcher tests.
pulsar/​table_view_impl.go Handles shutdown before logging and skips message handling on read errors.

Review effort: Balanced

Comment thread pulsar/table_view_impl.go Resolved
Comment thread pulsar/table_view_test.go Resolved
…rmal shutdown and skip nil messages on error
@zjxxzjwang

Copy link
Copy Markdown
Contributor Author

@crossoverJie Hello, I have made revisions based on the feedback. Please help me review them

@crossoverJie

Copy link
Copy Markdown
Member

@zjxxzjwang Could you rebase this onto the current master?

@zjxxzjwang

Copy link
Copy Markdown
Contributor Author

@zjxxzjwang Could you rebase this onto the current master?
@crossoverJie
I have rebased, please help me review.

1 similar comment
@zjxxzjwang

Copy link
Copy Markdown
Contributor Author

@zjxxzjwang Could you rebase this onto the current master?
@crossoverJie
I have rebased, please help me review.

@zjxxzjwang

Copy link
Copy Markdown
Contributor Author

@crossoverJie There are no other issues here, can you help me with the final approval

@crossoverJie crossoverJie added this to the 0.21.0 milestone Nov 3, 2026
@crossoverJie
crossoverJie merged commit 8ffcc53 into apache:master Nov 3, 2026
7 checks passed
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.

3 participants