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

node/bindnode: using Unwrap on some bindnode nodes can panic #339

Closed
mvdan opened this issue Jan 20, 2022 · 1 comment · Fixed by #431
Closed

node/bindnode: using Unwrap on some bindnode nodes can panic #339

mvdan opened this issue Jan 20, 2022 · 1 comment · Fixed by #431
Assignees

Comments

@mvdan
Copy link
Contributor

mvdan commented Jan 20, 2022

For example, I just tried using it on the nodes returned by MapIterator.Next, and I get:

panic: reflect.Value.Addr of unaddressable value

goroutine 1 [running]:
reflect.Value.Addr({0x58f980?, 0xc00012ac10?, 0x3?})
	/home/mvdan/tip/src/reflect/value.go:273 +0x65
github.com/ipld/go-ipld-prime/node/bindnode.Unwrap({0x604140?, 0xc00010f200?})
	/home/mvdan/go/pkg/mod/github.com/ipld/go-ipld-prime@v0.14.4/node/bindnode/api.go:113 +0x89
main.main()
	/home/mvdan/src/genericstest/main.go:53 +0x2d4
exit status 2

This is most likely because the MapIterator code path doesn't create datamodel.Node values with addressable Go values underneath.

I see three possible fixes:

  1. All code paths that create a node should ensure the Go value is addressable
  2. Unwrap should make an addressable copy of the value if it's not addressable
  3. Alter the API to show that some nodes can't be unwrapped

I don't like option 3, because at best we duplicate API, and at worst we'd break users. It's also harder to have to explain that some nodes aren't like others.

Option 2 would be the easiest, but also slightly inconsistent. If unwrapping one node twice returns two copies, but unwrapping another node doesn't make copies and returns the same pointer twice, then suddenly those two scenarios are very different.

So, option 1 seems best.

@mvdan mvdan changed the title node/bindnode: using Wrap on some nodes can panic node/bindnode: using Unwrap on some bindnode nodes can panic Feb 11, 2022
rvagg added a commit that referenced this issue May 24, 2022
Closes: #339

I can't repro the error in 339, so I'm adding this test and will close the issue
rvagg added a commit that referenced this issue May 24, 2022
Closes: #339

I can't repro the error in 339, so I'm adding this test and will close the
issue. Perhaps someone else can add something to this test that will trigger
the problem.
@rvagg
Copy link
Member

rvagg commented May 24, 2022

I've tried pretty hard to reproduce this but can't. Various types of both addressable and unaddressable values and unwrapping sub-nodes within a larger data structure, but can't. So I'm going to close this issue after adding #431 which has my attempts at getting to this error.

If someone else manages to come up with a case that causes this problem then we can fix it then.

@rvagg rvagg self-assigned this May 24, 2022
rvagg added a commit that referenced this issue May 25, 2022
Closes: #339

I can't repro the error in 339, so I'm adding this test and will close the
issue. Perhaps someone else can add something to this test that will trigger
the problem.
rvagg added a commit that referenced this issue May 25, 2022
Closes: #339

I can't repro the error in 339, so I'm adding this test and will close the
issue. Perhaps someone else can add something to this test that will trigger
the problem.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎉 Done
Development

Successfully merging a pull request may close this issue.

2 participants