shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

NacosClientRegisterRepository#persistInterface occurs NPE when the value of port is null

Open joewee opened this issue 5 years ago • 8 comments

Describe the bug

NacosClientRegisterRepository#persistInterface occurs NPE when the value of port is null ,so Integer auto-unboxing occurs NPE. I found that in ContextRegisterListener#buildMetaDataDTO method missing the parameter of port.

Environment

  • Soul version(s): 2.3.0-RELEASE

Steps to reproduce

Exception in thread "soul-disruptor-soul_disruptor_consumer_-17" java.lang.NullPointerException at org.dromara.soul.register.client.nacos.NacosClientRegisterRepository.persistInterface(NacosClientRegisterRepository.java:84) at org.dromara.soul.client.core.disruptor.subcriber.SoulClientMetadataExecutorSubscriber.executor(SoulClientMetadataExecutorSubscriber.java:53) at org.dromara.soul.client.core.disruptor.executor.RegisterClientConsumerExecutor.run(RegisterClientConsumerExecutor.java:43) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

Expected behavior

Debug logs

Click to expand
replace this line with your debug logs

joewee avatar May 17 '21 08:05 joewee

hi, please show you config ..

yu199195 avatar May 17 '21 08:05 yu199195

config Hi,follow figure is my configuration image btw,the ContextRegisterListener#buildMetaDataDTO method missed the port parameter ,so i think this may be a bug. private MetaDataRegisterDTO buildMetaDataDTO() { String contextPath = this.contextPath; String appName = env.getProperty("spring.application.name"); String path = contextPath + "/**"; return MetaDataRegisterDTO.builder() .contextPath(contextPath) .appName(appName) .path(path) .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .enabled(true) .ruleName(path) .build(); }

joewee avatar May 17 '21 08:05 joewee

thanks,we will see it.

freedom-xiao007 avatar May 17 '21 08:05 freedom-xiao007

what rpc you used? you dependency soul-client-xxxxx?

yu199195 avatar May 17 '21 08:05 yu199195

dependency rpc type is spring cloud,the dependency is org.dromara soul-register-client-nacos org.dromara soul-spring-boot-starter-client-springcloud

joewee avatar May 17 '21 09:05 joewee

in master? have problem?

yu199195 avatar May 17 '21 09:05 yu199195

The problem still exist in master branch when 'soul.client.props.isFull' is equls true in configuration file . Is the value of port optional or can be null when register the meta into nacos , If not i think in method buildMetaDataDTO() should set the port value like this: private MetaDataRegisterDTO buildMetaDataDTO() { String contextPath = this.contextPath; String appName = env.getProperty("spring.application.name"); Integer port = env.getProperty("server.port",Integer.class,8080); String path = contextPath + "/**"; return MetaDataRegisterDTO.builder() .contextPath(contextPath) .appName(appName) .path(path) .rpcType(RpcTypeEnum.SPRING_CLOUD.getName()) .enabled(true) .ruleName(path) .port(port) .build(); }

joewee avatar May 17 '21 13:05 joewee

What is you all config? please show the all config. Because .ocal cannot be reproduced.

give config like this:

server:
  port:
  address: 0.0.0.0

spring:
  application:
    name: springCloud-test
#  cloud:
#    nacos:
#      discovery:
#          server-addr: 127.0.0.1:8848


springCloud-test:
  ribbon.NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule

eureka:
  client:
    serviceUrl:
      defaultZone:  http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true    

soul:
  client:
    registerType: nacos #http #zookeeper #etcd #nacos #consul
    serverLists: localhost:8848 #http://localhost:9095 #localhost:2181 #http://localhost:2379 #localhost:8848
    props:
      contextPath: /springcloud
      port: ${server.port}
      nacosNameSpace: SoulRegisterCenter

logging:
  level:
    root: info
    org.dromara.soul: debug

freedom-xiao007 avatar May 18 '21 06:05 freedom-xiao007