NewMapFromID() needs a warning in docstring
notrobpike opened this issue · comments
Describe the bug
NewMapFromFD() closes the original fd. The doc warns not to use fd after calling it.
NewMapFromID() does the same thing. It has no such warning. I do believe (from inspection) that a subsequent new use of the ID is just fine, but if the caller were previously holding onto the fd from that map, it becomes invalid after NewMapFromID().
How to reproduce
see description
Version information
github.com/cilium/ebpf v0.13.2
Hi @notrobpike, could you show a small reproducer to demonstrate this behaviour?
BPF object IDs are system-wide. Calling NewMapFromID()
multiple times will yield independent *Map
objects, each represented by their own unique fd, pointing to the same map within the kernel. Closing one of the Maps cannot influence any of the others.
NewMapFromFD()
clones an fd, wraps it in a *Map
and closes the original fd to prevent it from being closed underneath us. This is completely different from NewMapFromID()
's functionality.
Moved to #1368.