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

Reader fails when seeking on /dev/stdin #17

Open
ckohnert opened this issue Feb 7, 2018 · 1 comment
Open

Reader fails when seeking on /dev/stdin #17

ckohnert opened this issue Feb 7, 2018 · 1 comment

Comments

@ckohnert
Copy link

ckohnert commented Feb 7, 2018

Go (as of 1.9 at least) reports os.Stdin as an io.Seeker, however when receiving stdin as a pipe, any seek attempt later on will fail. In msgp's case this breaks when valid input is being piped in.

I've whipped up an extra check that tries to detect this situation and fallback to non-io.Seeker appropriately.

patch-stdin-seeker-workaround.txt

@karrick
Copy link

karrick commented Feb 7, 2018

Great find. Looking at it, it seems like the standard library conflates the UNIX file descriptor concept with the file concept. Standard input does represent a file descriptor, but the standard library, for convenience, calls that an os.File, and Go's os.File struct are all, by definition implement the io.Seeker interface. From os/file.go:

var (
	Stdin  = NewFile(uintptr(syscall.Stdin), "/dev/stdin")
	Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")
	Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants