This is now controlled at the top level goji package: these packages are
not even compiled in when using App Engine. This is sensible, since
neither package is of any use there.
Expose an additional function, bind.WithFlag(), which allows callers to
use the previously-default "global flag" mode.
This change allows the bind string parser (etc.) to be used without
unwanted side effects. The behavior of the top-level "goji" package has
not been changed.
Fixes#47.
This eliminates the race condition mentioned in a54c913a by forbidding
duplicate binds to the same socket (well, at least in the sense that
attempting to do so will *always* result in an error instead of
nondeterministically resulting in an error).
This fixes a race condition between package bind and the garbage
collector, where if the garbage collector ran between einhornInit and
einhornBind, bind would fatal with the error "dup: bad file descriptor"
The core of the bug is that Go's os.File uses runtime.SetFinalizer to
register a callback to close the underlying file descriptor an os.File
points at when the os.File itself is being garbage collected. However,
the Einhorn initialization code in bind, in the process of ensuring that
every Einhorn-passed socket had CloseOnExec set on it, allocated
os.File's pointing at each of these passed file descriptors, but did not
keep references to these os.File's, allowing them to be garbage
collected. Subsequently, if you attempted to bind one of these sockets,
you'd find that it was no longer open.
This is the simplest fix to the bug, which is to only allocate an
os.File when we actually attempt to bind the socket. Note that there's
still a race condition here if you attempt to bind the same file
descriptor twice, since a GC between the two binds will likely cause the
file to be collected. Fortunately, that one can be worked around by
simply not allowing such silly behavior :). Another patch that makes
this more clear will follow.
Closes#29.
Package bind provides a convenient syntax for binding to sockets, as well as a
fair bit of magic to automatically Do The Right Thing in both development and
production.