Skip to content

Conversation

@benjirewis
Copy link
Member

@benjirewis benjirewis commented Oct 22, 2025

Changes type of resLoggers in Golang module library to be map[resource.Name]logging.Logger instead of map[resource.Resource]logging.Logger to avoid keying on resource.Resource and accidentally leaking resource.Resource objects when we forget to delete. Adds a missing delete for the map in RemoveResource. Adds a test to ensure that resLoggers looks as expected after adds, reconfigures, and removes.

@viambot viambot added the safe to test This pull request is marked safe to test from a trusted zone label Oct 22, 2025
@benjirewis benjirewis requested a review from dgottlieb October 22, 2025 16:21
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
Copy link
Member

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.

Copy link
Member Author

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())
Copy link
Member

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?

Copy link
Member Author

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?

@benjirewis benjirewis force-pushed the missing-resLoggers-delete branch from 2b92571 to 178de19 Compare October 29, 2025 18:25
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Oct 29, 2025
Copy link
Member Author

@benjirewis benjirewis left a 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
Copy link
Member Author

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())
Copy link
Member Author

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?

@benjirewis benjirewis force-pushed the missing-resLoggers-delete branch from 178de19 to a0dfbe4 Compare November 10, 2025 17:04
@viambot viambot added safe to test This pull request is marked safe to test from a trusted zone and removed safe to test This pull request is marked safe to test from a trusted zone labels Nov 10, 2025
Copy link
Member Author

@benjirewis benjirewis left a 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.

@dgottlieb
Copy link
Member

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.

@benjirewis
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test This pull request is marked safe to test from a trusted zone

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants