Skip to content

Avoid skipping a storage due to identical string representations#5934

Closed
ankon wants to merge 2 commits intocaddyserver:masterfrom
framer:fix/storage-cleanup-avoid-skipping
Closed

Avoid skipping a storage due to identical string representations#5934
ankon wants to merge 2 commits intocaddyserver:masterfrom
framer:fix/storage-cleanup-avoid-skipping

Conversation

@ankon
Copy link
Copy Markdown
Contributor

@ankon ankon commented Nov 9, 2023

fmt.Sprintf("%v", thing) will use a fmt.Stringer implementation in thing, which means that we cannot easily assume that this value is going to be unique here and can be used to deduplicate the storages.

Instead: Use a map[interface{}]struct{} as we anyways have an interface, and interfaces are perfectly fine map keys.

As a side-effect: Implementors of storage can now implement fmt.Stringer safely, and get the expected output here.

fmt.Sprintf("%v", thing) will use a fmt.Stringer implementation in thing, which means
that we cannot easily assume that this value is going to be unique here and can be used
to deduplicate the storages.

Instead: Use a `map[interface{}]struct{}` as we anyways have an interface, and interfaces
are perfectly fine map keys.
@ankon ankon marked this pull request as draft November 9, 2023 19:15
@ankon ankon marked this pull request as ready for review November 9, 2023 19:17
@ankon
Copy link
Copy Markdown
Contributor Author

ankon commented Nov 9, 2023

Copy link
Copy Markdown
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Thanks!

Hmm, yes, this is probably better; although, I wonder if this is too strict of a comparison. It uses the pointer to the value as the key, so if we have 2 identical storage configurations with different pointers (like they are configured in different automation policies) then it won't deduplicate properly.

Maybe that is fine. It's probably better to clean twice than to skip cleaning entirely. (Unless the storage mechanism is expensive, like a cloud DB or something.)

My original hope was that the %v would be able to capture a representation of the storage config in a general way.

Anyway, I think overall, this change is probably good.

If you think the issue I mention above would be a problem in your case, though, let me know and we can figure something out.

Comment thread modules/caddytls/tls.go Outdated
@ankon
Copy link
Copy Markdown
Contributor Author

ankon commented Nov 9, 2023

Unless the storage mechanism is expensive, like a cloud DB or something.

Yeah. Well. :)

@ankon
Copy link
Copy Markdown
Contributor Author

ankon commented Nov 9, 2023

My original hope was that the %v would be able to capture a representation of the storage config in a general way.

I think that's a good goal actually, but maybe that should then be a (optional) requirement on the storage implementation: If you implement interface StorageId, we promise to use that to track storage identity, and you promise to give a sane value.

I'm wondering whether it could be done backwards-compatible, but I really think the foot-shooting potential of falling back to fmt.Stringer is a bit too high.

@mholt
Copy link
Copy Markdown
Member

mholt commented Nov 14, 2023

As mentioned in Slack, I have a proper fix inbound, I think. Stay tuned in the next day or so for that!

@mholt
Copy link
Copy Markdown
Member

mholt commented Nov 28, 2023

Gently closing this in favor of #5940 -- we can reopen this if needed, of course. Thanks for helping! 😀

@mholt mholt closed this Nov 28, 2023
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.

2 participants