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

ServiceConfig duplicate export produces misleading exception #3629

Closed
JerryChin opened this issue Mar 11, 2019 · 5 comments · Fixed by #5079
Closed

ServiceConfig duplicate export produces misleading exception #3629

JerryChin opened this issue Mar 11, 2019 · 5 comments · Fixed by #5079

Comments

@JerryChin
Copy link

JerryChin commented Mar 11, 2019

I mistakenly exported ServiceConfig twice, the second call produces the following exception which makes no sense:

java.lang.reflect.InvocationTargetException: null
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_91]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_91]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_91]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_91]
	at org.apache.dubbo.config.AbstractConfig.refresh(AbstractConfig.java:568) [dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.ServiceConfig.checkAndUpdateSubConfigs(ServiceConfig.java:272) [dubbo-2.7.0.jar:2.7.0]
	at org.apache.dubbo.config.ServiceConfig.export(ServiceConfig.java:328) [dubbo-2.7.0.jar:2.7.0]
	at xx.xx.xx.xx.rpc.NodeRpcServerV3.start(NodeRpcServerV3.java:298) [classes/:?]
	at xx.xx.xx.xx.rpc.NodeRpcV3Test.init(NodeRpcV3Test.java:21) [test-classes/:?]
	....
Caused by: java.lang.IllegalArgumentException: Unsupported generic type false
	at org.apache.dubbo.config.ServiceConfig.setGeneric(ServiceConfig.java:959) ~[dubbo-2.7.0.jar:2.7.0]
	... 67 more

It took me at least one hour to locate the root cause.

Dubbo version: 2.7.0

I've crafted a demo for this issue at this repo.

@kexianjun
Copy link
Member

sure this exception is misleading,do you have any idea to improve this?

@JerryChin
Copy link
Author

JerryChin commented Mar 12, 2019

@kexianjun

I do have some ideas after reviewing the source code of ServiceConfig.

First, the existing implementation by using two variables for controlling ServiceConfig exporting state is not only awkward to code, but also can theoretically lead invalid state transitions (exported and export both simultaneously true or false).

Secondly, the exported is set in doExport() method which could be called asynchronously, this makes it hard to refactor to prevent duplication exporting.

Okay, there's not "last but not least".

I'll suggest to introduce the following changes:

  1. refactor the two variables aforementioned into one AtomicInteger variable.
  2. compare and set exporting state in export() and unexport() methods before doing anything.
  3. it's obviously to see that we can now safely remove the synchronized from the two methods.

@kexianjun
Copy link
Member

@kexianjun

I do have some ideas after reviewing the source code of ServiceConfig.

First, the existing implementation by using two variables for controlling ServiceConfig exporting state is not only awkward to code, but also can theoretically lead invalid state transitions (exported and export both simultaneously true or false).

Secondly, the exported is set in doExport() method which could be called asynchronously, this makes it hard to refactor to prevent duplication exporting.

Okay, there's not "last but not least".

I'll suggest to introduce the following changes:

  1. refactor the two variables aforementioned into one AtomicInteger variable.
  2. compare and set exporting state in export() and unexport() methods before doing anything.
  3. it's obviously to see that we can now safely remove the synchronized from the two methods.

could you pls send a pr about your suggestion?

@JerryChin
Copy link
Author

I'll try to work out a PR for this issue this evening. @kexianjun

JerryChin added a commit to JerryChin/incubator-dubbo that referenced this issue Mar 14, 2019
JerryChin added a commit to JerryChin/incubator-dubbo that referenced this issue Mar 14, 2019
@JerryChin JerryChin changed the title ServiceConfig duplicate export produces irrelevant exception ServiceConfig duplicate export produces misleading exception Mar 14, 2019
JerryChin added a commit to JerryChin/incubator-dubbo that referenced this issue Mar 14, 2019
@tswstarplanet
Copy link
Contributor

I think PR 3629 doesn't catch the reason. I submit a new pr for the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants