facebook / facebook/watchman

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

Open
#13 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
13.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

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)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.