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

Mount Instantiate doesn't support reference subfields of mount #161

Open
walldiss opened this issue Aug 11, 2023 · 0 comments
Open

Mount Instantiate doesn't support reference subfields of mount #161

walldiss opened this issue Aug 11, 2023 · 0 comments

Comments

@walldiss
Copy link

Mount Instantiate func, uses clone() function to initialise new value of mount from registered type template. clone() func
creates a copy of each field of mount and thats it. So it assumes, that underlying type of mount should have all fields with value type. If any fields of template is a reference type (pointer, interface, map...), it will copy the reference value (e.g. pointer). In our case it resulted in all mounts to share same copy of pointer type and returning same mount on Get call, regardless of key.

So for example type

type myMount struct{
  mount.Mount
} 

It fully implements mount.Mount interface (thx to embedding). The inner field being interface will be copied by reference. So all shards will have same pointer of the inner interface.

Few ideas how fix:

  • do smarter cloning of mount type
  • disallow reference fields inside mount type (could be checked on registration).
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

No branches or pull requests

1 participant