Skip to content

blocked on reading when output is piped (line buffering?) #13

Open

Description

@fugalh

When I pipe watchman -pj --no-pretty, it hangs reading from the socket

$ strace -- watchman -pj --server-encoding=json --no-pretty | cat
...
read(0, "[\"subscribe\", \"/tmp/foo\", \"foxy\""..., 1024) = 79
read(0, "", 1024)                       = 0
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path="/var/facebook/watchman/fugalh"}, 110) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa4433b9000
write(3, "[\"subscribe\",\"/tmp/foo\",\"foxy\",{"..., 72) = 72
read(3, "{\"version\":\"2.9.1\",\"subscribe\":\""..., 1048576) = 702
fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fa4434c9000
read(3, 

At that point it just hangs. Note the piping into cat; when it runs with a tty as stdout it works fine:

$ strace -- watchman -pj --server-encoding=json --no-pretty
...
read(0, "[\"subscribe\", \"/tmp/foo\", \"foxy\""..., 1024) = 79
read(0, "", 1024)                       = 0
socket(PF_FILE, SOCK_STREAM, 0)         = 3
connect(3, {sa_family=AF_FILE, path="/var/facebook/watchman/fugalh"}, 110) = 0
setsockopt(3, SOL_SOCKET, SO_RCVBUF, [1048576], 4) = 0
mmap(NULL, 1052672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f026bcd2000
write(3, "[\"subscribe\",\"/tmp/foo\",\"foxy\",{"..., 72) = 72
read(3, "{\"version\":\"2.9.1\",\"subscribe\":\""..., 1048576) = 702
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f026bde2000
write(1, "{\"version\":\"2.9.1\",\"subscribe\":\""..., 72) = 72
write(1, "{\"version\":\"2.9.1\",\"clock\":\"c:13"..., 630) = 630
read(3, 

Smells like line buffering, but I'm not sure how that would make a difference here - we read 702 bytes from fd 3 both times, but the first time we try to read again instead of trying to write anything.

(Linux)

Activity

  1. fugalh commented on Oct 25, 2013

    @fugalh
    ContributorAuthor

    Almost forgot to mention - it doesn't do this without --no-pretty. So it has something to do with the non-pretty codepath.

  2. wincent commented on Aug 4, 2015

    @wincent
    Contributor

    I suspect this may not be a bug (see this Stackoverflow answer).

  3. wez commented on Aug 5, 2015

    @wez
    Contributor

    This might get a bit better when we merge the Windows branch in

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions