Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic config /reference_config.go line 105 #2439

Closed
ijustyce opened this issue Oct 9, 2023 · 6 comments
Closed

panic config /reference_config.go line 105 #2439

ijustyce opened this issue Oct 9, 2023 · 6 comments

Comments

@ijustyce
Copy link

ijustyce commented Oct 9, 2023

Code show as below, consumer field is a pointer so may be nil.

image
@DMwangnima
Copy link
Contributor

@ijustyce ReferenceConfig must be defined within ConsumerConfig, as this dubbogo.yml shows:

dubbo:
  registries:
    demoZK:
      protocol: zookeeper
      timeout: 3s
      address: 127.0.0.1:2181
  consumer:
    references:
      GreeterClientImpl:
        protocol: tri
        interface: com.apache.dubbo.sample.basic.IGreeter

ReferenceConfig.Init() is invoked by ConsumerConfig.Init(). As a result, there is no problem with nil pointer.

@ijustyce
Copy link
Author

ijustyce commented Oct 9, 2023

@ijustyce ReferenceConfig must be defined within ConsumerConfig, as this dubbogo.yml shows:

dubbo:
  registries:
    demoZK:
      protocol: zookeeper
      timeout: 3s
      address: 127.0.0.1:2181
  consumer:
    references:
      GreeterClientImpl:
        protocol: tri
        interface: com.apache.dubbo.sample.basic.IGreeter

ReferenceConfig.Init() is invoked by ConsumerConfig.Init(). As a result, there is no problem with nil pointer.

In our case, I'm responsible for config module and one of my colleagues told me if there is no consumer config then panic at ReferenceConfig.Init. As ReferenceConfig.Init() is a public method so we can call it manually and root.Consumer may be nil as it is a pointer.

@DMwangnima
Copy link
Contributor

DMwangnima commented Oct 9, 2023

@ijustyce Got it. We would fix it as soon as possible.
By the way, I appreciate that you could show us some code snippets about using ReferenceConfig directly without ConsumerConfig(removing business-related parts)? We are designing new API so that real user cases would help a lot.

@ijustyce
Copy link
Author

ijustyce commented Oct 9, 2023

@ijustyce Got it. We would fix it as soon as possible. By the way, I appreciate that you could show us some code snippets about using ReferenceConfig directly without ConsumerConfig(removing business-related parts)? We are designing new API so that real user cases would help a lot.

rootConfig, _ := config2.Bind[*config.RootConfig]("root-prefix")
//	our code ...
refConfig, _ := config2.Bind[*config.ReferenceConfig]("ref-prefix")
_ = rootConfig.Init()
_= refConfig.Init(rootConfig)
//	our code ...

It's hard to answer person after person's question and tell them how to avoid it, as we all know users often use things in ways we never thought of.

@DMwangnima
Copy link
Contributor

Thank you very much for your case! By the way, after refConfig.Init(rootConfig), you just make use of refConfig.Export(cli) or wrap it with some additional procedures to make it act as call in other framework?

@ijustyce
Copy link
Author

Thank you very much for your case! By the way, after refConfig.Init(rootConfig), you just make use of refConfig.Export(cli) or wrap it with some additional procedures to make it act as call in other framework?

Call refConfig.GenericLoad("xxx"), no wrap.

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

No branches or pull requests

2 participants