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

[qfix] Fix panic on metadata chain elements double Close #1036

Merged

Conversation

Bolodya1997
Copy link

Description

Fixes metadata.Map(ctx) panic on double Close.

Issue link

Related to kind integration tests failure - https://github.com/networkservicemesh/integration-k8s-kind/runs/3136678807?check_suite_focus=true.

How Has This Been Tested?

  • Added unit testing to cover
  • Tested manually
  • Tested by integration testing
  • Have not tested

Types of changes

  • Bug fix
  • New functionallity
  • Documentation
  • Refactoring
  • CI

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
if err != nil {
del(ctx, connID, &m.Map)
m.Map.Delete(connID)
Copy link
Member

Choose a reason for hiding this comment

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

How is the Close call going to access the metadata it needs to clean up resources? Before it was guaranteed access to that data by del()... now it will not have it at all and we should expect to leak all resources...

Copy link
Author

Choose a reason for hiding this comment

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

Close is currently making:

next.Server(ctx).Close(store(…), conn)

So it has access to metadata.
Actually the problem before was Close making:

next.Server(ctx).Close(del(…), conn)

And so on double Close there were no metadata.

md, _ := mdMap.LoadAndDelete(id)
return context.WithValue(parent, metaDataKey{}, md)
}
return parent
Copy link
Member

Choose a reason for hiding this comment

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

Its seems to me the better fix here would be:

Suggested change
return parent
return context.WithValue(parent,metaDataKey{},&metaData{})

Copy link
Member

Choose a reason for hiding this comment

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

I don't think you quite understood my suggestion... I believe that just this change will solve your panic issue, no need for other changes. Small, simple, targeted.

Copy link
Member

Choose a reason for hiding this comment

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

Oh wait... I read to quickly... you did fix this :)

Copy link
Author

Choose a reason for hiding this comment

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

So actually this fix leads to the same error, because on L40 we are getting md == nil and so on L41 we just storing it into the context.
But this direction looks better, so:

if _, ok := parent.Value(metaDataKey{}).(*metaData); !ok {
	if md, ok := mdMap.LoadAndDelete(id); ok {
		return context.WithValue(parent, metaDataKey{}, md)
	}
	return context.WithValue(parent, metaDataKey{}, new(metaData))
}
return parent

Signed-off-by: Vladimir Popov <vladimir.popov@xored.com>
@edwarnicke edwarnicke merged commit 3af6e1b into networkservicemesh:main Jul 23, 2021
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

Successfully merging this pull request may close these issues.

3 participants