Skip to content

Conversation

@ericgribkoff
Copy link
Contributor

This addresses #2689. ServerReflectionIndex is now immutable, and its reference is replaced by a new instance when changes are detected.

I also fixed some poor formatting choices present in the earlier code, primarily the tests - I don't think the changes are too invasive, given that much of the code has genuinely been changed here, and the formatting already popped up as an issue on #2657.

* detected. A change is any addition or removal in the set of file descriptors attached to the
* mutable services or a change in the service names.
*/
private void updateIndexIfNecessary() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not thread-safe. serverReflectionInfo() may be called from multiple threads. Make it synchronized and put @GuardedBy on serverReflectionIndex?

You'd also need to return serverReflectionIndex from this method, to avoid grabbing the lock again in serverReflectionInfo(). Alternatively you could use a volatile, but meh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lock and @GuardedBy added.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For posterity: this is actually thread-safe, due to final usage, but it isn't obviously so and it does take some effort to show it is safe. So we're still going to change it to something more obviously correct.

@ejona86
Copy link
Member

ejona86 commented Mar 1, 2017

Travis is broken right now. Feel free to ignore it. It should be fine in a few more hours.

@ericgribkoff ericgribkoff merged commit e345273 into grpc:master Mar 1, 2017
@ericgribkoff ericgribkoff deleted the reflection_fix branch March 1, 2017 04:05
@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants