Skip to content

[Kuberenetes Client] The constructor of kubernetes may referenced to null HttpClientHandler #307

Closed
@Incarnation-p-lee

Description

@Incarnation-p-lee

The constructor will invoke InitializeFromConfig, and the method will reference to HttpClientHandler from base class ServiceClient.

        public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient, bool disposeHttpClient) : this(httpClient, disposeHttpClient)
        {
            ValidateConfig(config);
            CaCerts = config.SslCaCerts;
            SkipTlsVerify = config.SkipTlsVerify;
            InitializeFromConfig(config);
        }

But the related constructor of base class ServiceClient only create new handler only if client is null, so there may be one path that makes HttpClientHandler to be null.

        protected void InitializeHttpClient(HttpClient httpClient, HttpClientHandler httpClientHandler, params DelegatingHandler[] handlers)
        {
            //Init lock object
            lockUserAgent = new object();


            if (httpClient == null)
            {
                if (httpClientHandler == null)
                {
                    httpClientHandler = CreateRootHandler();
                }


                HttpClientHandler = httpClientHandler;


                DelegatingHandler currentHandler = CreateHttpHandlerPipeline(httpClientHandler, handlers);


                HttpClient = new HttpClient(currentHandler, false);
                FirstMessageHandler = currentHandler;
            }
            else
            {
                HttpClient = httpClient;
            }


            //Set Default info in user agent
            SetDefaultAgentInfo();
        }

https://github.com/Azure/azure-sdk-for-net/blob/45cdad6bc3f20b36220d303a44f99895bdba28b7/sdk/mgmtcommon/ClientRuntime/ClientRuntime/ServiceClient.cs#L341-L367

So could you please help to confirm is this expected ? Or How can I pass the httpClient in a correct way ? Thanks a lot.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions