Skip to content

How does NewMapFromFD() work? #1368

Closed Answered by ti-mo
notrobpike asked this question in Q&A
Discussion options

You must be logged in to vote

@notrobpike Scratch what I said about NewMapFromFD calling dup() and close(), I didn't have the code in front of me. We have a few abstractions that take a raw fd from the caller and dup() it, but I can't find any cases where we close a user-provided fd.

The reason we warn the caller about not reusing a raw fd after passing it into e.g. NewMapFromFD() is that the underlying fd becomes bound to the lifecycle of the *Map from there on out. If the Map gets garbage collected or explicitly Close()d, that will invalidate the original fd.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@notrobpike
Comment options

Answer selected by notrobpike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants