Skip to content

fix: replace panic with proper error handling in RPC client and lookup service - #1403

Merged
RobertIndie merged 4 commits into
apache:masterfrom
RobertIndie:fix-rpc-client-panic
Jul 31, 2025
Merged

RobertIndie merged 4 commits into
apache:masterfrom
RobertIndie:fix-rpc-client-panic

Conversation

@RobertIndie

@RobertIndie RobertIndie commented Jul 30, 2025 •

Copy link
Copy Markdown
Member

Motivation

Fixes #1402

The current implementation uses panic() calls in several critical code paths within the RPC client and lookup service, which can cause the entire application to crash when encountering invalid URLs or configuration errors. This is not a good practice for a client library as it makes the application unstable and difficult to handle gracefully.

The main issues addressed:

  • NewRPCClient() panics when creating lookup service fails
  • LookupService() panics when parsing invalid URLs or creating lookup services
  • NewLookupService() panics for invalid URL schemes

Modifications

  • RPC Client Interface: Modified LookupService() method signature to return (LookupService, error) instead of just LookupService
  • NewRPCClient: Changed to return (RPCClient, error) and handle lookup service creation errors properly
  • LookupService Implementation: Replaced all panic() calls with proper error returns and descriptive error messages

Verifying this change

  • Make sure that the change passes the CI checks.

(Please pick either of the following options)

This change is a trivial rework / code cleanup without any test coverage.

(or)

This change is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(example:)

  • Added integration tests for end-to-end deployment with large payloads (10MB)
  • Extended integration test for recovery after broker failure

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

If yes was chosen, please highlight the changes

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API: (yes / no)
  • The schema: (yes / no / don't know)
  • The default values of configurations: (yes / no)
  • The wire protocol: (yes / no)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / GoDocs / not documented)
  • If a feature is not applicable for documentation, explain why?
  • If a feature is not documented yet in this PR, please create a followup issue for adding the documentation

@RobertIndie RobertIndie self-assigned this Jul 30, 2025
@RobertIndie
RobertIndie force-pushed the fix-rpc-client-panic branch from 012a048 to a5dd90f Compare July 30, 2025 10:26
@RobertIndie
RobertIndie marked this pull request as ready for review July 30, 2025 10:48

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.

Pull Request Overview

This pull request replaces panic-based error handling with proper error returns in the RPC client and lookup service components to improve application stability and graceful error handling.

  • Modified RPC client interface to return errors instead of panicking on invalid URLs or configuration issues
  • Updated all callers to handle the new error returns from LookupService() and NewRPCClient()
  • Added comprehensive test coverage for error scenarios that previously caused panics

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pulsar/internal/rpc_client.go Modified LookupService() and NewRPCClient() to return errors instead of panicking
pulsar/internal/rpc_client_test.go Added tests to verify error handling for invalid URLs and schemes
pulsar/client_impl.go Updated client initialization to handle RPC client creation errors
pulsar/producer_partition.go Modified lookupTopic() to handle LookupService() error returns
pulsar/consumer_partition.go Updated lookupTopic() to handle LookupService() error returns
pulsar/internal/lookup_service_test.go Updated mock implementations to match new interface signature
Comments suppressed due to low confidence (2)

pulsar/consumer_partition.go:1941

  • The error handling path for LookupService() in consumer partition's lookupTopic() method lacks test coverage. Consider adding tests to verify this error scenario is handled properly.
		lr, err := lookupService.Lookup(pc.topic)

pulsar/producer_partition.go:251

  • The error handling path for LookupService() in producer partition's lookupTopic() method lacks test coverage. Consider adding tests to verify this error scenario is handled properly.
		lr, err := lookupService.Lookup(p.topic)

@crossoverJie crossoverJie added this to the v0.17.0 milestone Jul 31, 2025
@RobertIndie
RobertIndie merged commit 06f4dd8 into apache:master Jul 31, 2025
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.

[BUG] rpc_client will panic the whole process when met errors

3 participants