dagstore icon indicating copy to clipboard operation
dagstore copied to clipboard

Mount Instantiate doesn't support reference subfields of mount

Open walldiss opened this issue 1 year ago • 0 comments

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).

walldiss avatar Aug 11 '23 12:08 walldiss