Skip to content

[feat] Authentication implementations such as AuthenticationOAuth2 should support sharing thread pools or DNS cache #24795

Closed
3pacccccc/pulsar
#35

Description

@lhotari

Search before reporting

  • I searched in the issues and found nothing similar.

Motivation

PIP-234 implementation #24790 adds support for sharing thread pools and DNS resolver/cache across multiple client instances. However, authentication implementations such as AuthenticationOAuth2 create new thread pools and DNS resolvers/caches. This isn't desired, since it would be useful to be able to share the Netty Event Loop and configure the DNS settings in the client and use them for all Pulsar client DNS lookups, at least for most common use cases.

Solution

The org.apache.pulsar.client.api.Authentication interface could be changed so that the "container" could pass a context instance with contains methods to lookup shared instances.

    /**
     * Initialize the authentication provider.
     */
    default void start(AuthenticationInitContext context) throws PulsarClientException {
        start();
    }

    /**
     * Initialize the authentication provider.
     */
    void start() throws PulsarClientException;

The AuthenticationInitContext could contain generic "getService" and "getServiceByName" methods:

public interface AuthenticationInitContext {
    <T> Optional<T> getService(Class<T> serviceClass);
    <T> Optional<T> getServiceByName(Class<T> serviceClass, String name);
}

This solution could be used to pass the Netty event loop, DNS resolver and Timer to be shared in the AuthenticationOAuth2 implementation.

Alternatives

No response

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/enhancement
    on Sep 27, 2025
  2. AradhyaSharma31 commented on Oct 15, 2025

    @AradhyaSharma31

    Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

  3. lhotari commented on Oct 15, 2025

    @lhotari
    MemberAuthor

    Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

    @AradhyaSharma31 Thanks for volunteering. This might not be the best way to start contributing to Pulsar, but you can always give it a try. The Pulsar Contributor guide is available at https://pulsar.apache.org/contribute/ with multiple instructions. For example:

    You can join the dev channel on Pulsar Slack to coordinate work. I might not be able to respond immediately, but I usually put effort to help if someone is putting effort to contribute.

  4. 3pacccccc commented on Nov 26, 2025

    @3pacccccc
    Contributor

    Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

    Hi, are you still working on this issue?

  5. lhotari commented on Nov 26, 2025

    @lhotari
    MemberAuthor

    Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

    Hi, are you still working on this issue?

    @3pacccccc Not at the moment. btw. Please also review the comment in #24944 (comment) .

  6. 3pacccccc commented on Nov 26, 2025

    @3pacccccc
    Contributor

    Hi @lhotari, I would like to work on this issue. I plan to start exploring a solution and would greatly appreciate any guidance or context you can provide. Thank you

    Hi, are you still working on this issue?

    @3pacccccc Not at the moment. btw. Please also review the comment in #24944 (comment) .

    @lhotari OK, I see, I'll working on this.

  7. AradhyaSharma31 commented on Nov 28, 2025

    @AradhyaSharma31

    Hi, I’ve completed the work for this issue. I was busy for a while, so I hadn’t pushed it yet.
    If it’s still useful, I can open a PR. Let me know if I should proceed or if the current assignee is already on it.

  8. lhotari commented on Nov 28, 2025

    @lhotari
    MemberAuthor

    Hi, I’ve completed the work for this issue. I was busy for a while, so I hadn’t pushed it yet. If it’s still useful, I can open a PR. Let me know if I should proceed or if the current assignee is already on it.

    @AradhyaSharma31 Sure, please go ahead and open a PR. It's recommended to run tests in your own fork as the first step for larger changes, please see https://pulsar.apache.org/contribute/personal-ci/. Please also check comments at #24944 (comment).

  9. AradhyaSharma31 commented on Nov 28, 2025

    @AradhyaSharma31

    @lhotari Thanks for the guidance. After reviewing the changes in #24944 , I see that parts of my implementation conflict with the updated OAuth2 structure. I’ll refactor my solution to align with the new code and then open the PR.

    I’ve been running mock tests and Pulsar CI locally when validating changes. If there are additional checks or recommended steps I should follow, please let me know.

  10. lhotari commented on Nov 28, 2025

    @lhotari
    MemberAuthor

    I’ve been running mock tests and Pulsar CI locally when validating changes. If there are additional checks or recommended steps I should follow, please let me know.

    @AradhyaSharma31 Please follow the instructions in https://pulsar.apache.org/contribute/personal-ci/ to first open a PR in your own fork and run the full Pulsar CI GitHub Actions pipeline there. It's not a very feasible solution to run the full pipeline locally since it requires about 10 hours of compute time to run all tests. You get this for free with GitHub Actions.

  11. lhotari commented on Mar 19, 2026

    @lhotari
    MemberAuthor

    Slightly related to #19429

  12. merlimat commented on Oct 23, 2026

    @merlimat
    Contributor

    Thanks @lhotari for raising this. PIP-478 (#25890) added this, and #26282 implemented it: the client now hands authentication plugins its shared services, and AuthenticationOAuth2 gets its HTTP client from the client's framework factory. That client shares the owning PulsarClient/PulsarAdmin's event loop, timer and DNS resolver instead of creating its own. This is available since 5.0.0. If something is still missing, please reopen or open a new issue.

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

Metadata

Metadata

Assignees

Labels

type/enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions