-
Notifications
You must be signed in to change notification settings - Fork 126
RSDK-12383 Stop leaking resource.Resources with resLoggers in module code #5398
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
base: main
Are you sure you want to change the base?
RSDK-12383 Stop leaking resource.Resources with resLoggers in module code #5398
Conversation
module/module.go
Outdated
| handlers HandlerMap | ||
| collections map[resource.API]resource.APIResourceCollection[resource.Resource] | ||
| resLoggers map[resource.Resource]logging.Logger | ||
| resLoggers map[resource.Name]logging.Logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why you did this, but this requires a different kind of analysis.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
different kind of analysis
Do you mean proving (or at least being somewhat sure) that we have a bijection of resource names to loggers in a single Golang module? Whereas mapping resource.Resource:logging.Logger is more "obviously" correct in that we don't have to ask the question "do names always uniquely and correctly identify resources in all usages of resLoggers"?
And, if so, are you saying that to suggest I don't try to prove that since it's not worth the effort/commitment to that invariant?
module/module.go
Outdated
|
|
||
| delete(m.streamSourceByName, res.Name()) | ||
| delete(m.activeResourceStreams, res.Name()) | ||
| delete(m.resLoggers, res.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it guaranteed that all requests for a resource are drained before RemoveResource can be processed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question; I believe the answer is no. I just tried RemoveResourceing a Golang modular component in the middle of its DoCommand invocation. We certainly don't have any logic now that waits for that DoCommand to finish before completing RemoveResource.
Are you asking that question because you're concerned that deleteing the logger from the resLoggers map could cause the logger to be garbage collected while a request is still using it?
2b92571 to
178de19
Compare
benjirewis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I've responded to your questions with, unfortunately, more questions 😆 .
module/module.go
Outdated
| handlers HandlerMap | ||
| collections map[resource.API]resource.APIResourceCollection[resource.Resource] | ||
| resLoggers map[resource.Resource]logging.Logger | ||
| resLoggers map[resource.Name]logging.Logger |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
different kind of analysis
Do you mean proving (or at least being somewhat sure) that we have a bijection of resource names to loggers in a single Golang module? Whereas mapping resource.Resource:logging.Logger is more "obviously" correct in that we don't have to ask the question "do names always uniquely and correctly identify resources in all usages of resLoggers"?
And, if so, are you saying that to suggest I don't try to prove that since it's not worth the effort/commitment to that invariant?
module/module.go
Outdated
|
|
||
| delete(m.streamSourceByName, res.Name()) | ||
| delete(m.activeResourceStreams, res.Name()) | ||
| delete(m.resLoggers, res.Name()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question; I believe the answer is no. I just tried RemoveResourceing a Golang modular component in the middle of its DoCommand invocation. We certainly don't have any logic now that waits for that DoCommand to finish before completing RemoveResource.
Are you asking that question because you're concerned that deleteing the logger from the resLoggers map could cause the logger to be garbage collected while a request is still using it?
178de19 to
a0dfbe4
Compare
benjirewis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dgottlieb apologies for delay on this PR. I retained the original map typing and just added some missing deletes on resource rebuild and removal. Let me know what you think.
|
Sorry @benjirewis , I never responded to those questions. Or maybe we talked offline, can't recall! I actually have a PR that might be addressing this (need to look closer again). But this PR was why I noticed in the first place. I'll know better later this week. |
|
No worries! Gotcha, will hold off on this PR until EoW, then. Let me know if you need more eyes on your PR for RSDK-12391. |
Changes type of
resLoggersin Golang module library to bemap[resource.Name]logging.Loggerinstead ofmap[resource.Resource]logging.Loggerto avoid keying onresource.Resourceand accidentally leakingresource.Resourceobjects when we forget todelete. Adds a missingdeletefor the map inRemoveResource. Adds a test to ensure thatresLoggerslooks as expected after adds, reconfigures, and removes.