Skip to content

Fix "Failed to write while dumping service window: Broken pipe" - #351

Merged
JeffLIrion merged 1 commit into
JeffLIrion:masterfrom
Liborsaf:master
Oct 27, 2024
Merged

Fix "Failed to write while dumping service window: Broken pipe"#351
JeffLIrion merged 1 commit into
JeffLIrion:masterfrom
Liborsaf:master

Conversation

@Liborsaf

Copy link
Copy Markdown
Contributor

Fixes #349

@JeffLIrion
JeffLIrion merged commit c2ca4c4 into JeffLIrion:master Oct 27, 2024
tgrushka added a commit to dra11y/python-androidtv that referenced this pull request Aug 2, 2026
This PR:
- fixes a broken pipe like in JeffLIrion#351, but from `grep -q` instead of `grep -m 1`
- uses a much more efficient call to get idle state

On Android 14, both `dumpsys power` greps no longer match. It prints
`Display Power: com.android.server.power.PowerManagerService$1@a8a75e6` with
no `state=` field, and `mScreenOn=true` is gone. So each poll, every 10
seconds, falls back to `dumpsys display`, a much more expensive call.

Because `grep -q` terminates on first match, the pipe is broken, resulting in
a stack trace every 10 seconds that looks like:

```
W FastPrintWriter: Write failure
W FastPrintWriter: java.io.IOException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:651)
W FastPrintWriter: 	at java.io.FileOutputStream.write(FileOutputStream.java:432)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:355)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:378)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:413)
W FastPrintWriter: 	at android.os.Binder.dump(Binder.java:1158)
W FastPrintWriter: 	at android.os.Binder.onTransact(Binder.java:1022)
W FastPrintWriter: Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:646)
W FastPrintWriter: 	... 9 more
```

This PR fixes the issue:
- uses `dumpsys deviceidle get screen` to check power state, which is cheap
  and has been available since Android 7
- removes `-q` so grep will not stop on first match and cause broken pipe
tgrushka added a commit to dra11y/python-androidtv that referenced this pull request Aug 2, 2026
This PR:
- fixes a broken pipe like in JeffLIrion#351, but from `grep -q` instead of `grep -m 1`
- uses a much more efficient call to get screen state

On Android 14, both `dumpsys power` greps no longer match. It prints
`Display Power: com.android.server.power.PowerManagerService$1@a8a75e6` with
no `state=` field, and `mScreenOn=true` is gone. So each poll, every 10
seconds, falls back to `dumpsys display`, a much more expensive call.

Because `grep -q` terminates on first match, the pipe is broken, resulting in
a stack trace every 10 seconds that looks like:

```
W FastPrintWriter: Write failure
W FastPrintWriter: java.io.IOException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:651)
W FastPrintWriter: 	at java.io.FileOutputStream.write(FileOutputStream.java:432)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:355)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:378)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:413)
W FastPrintWriter: 	at android.os.Binder.dump(Binder.java:1158)
W FastPrintWriter: 	at android.os.Binder.onTransact(Binder.java:1022)
W FastPrintWriter: Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:646)
W FastPrintWriter: 	... 9 more
```

This PR fixes the issue:
- uses `dumpsys deviceidle get screen` to check power state, which is cheap
  and has been available since Android 7
- removes `-q` so grep will not stop on first match and cause broken pipe
tgrushka added a commit to dra11y/python-androidtv that referenced this pull request Aug 2, 2026
This PR:
- fixes a broken pipe like in JeffLIrion#351, but from `grep -q` instead of `grep -m 1`
- uses a much more efficient call to get screen state

On Android 14, both `dumpsys power` greps no longer match. It prints
`Display Power: com.android.server.power.PowerManagerService$1@a8a75e6` with
no `state=` field, and `mScreenOn=true` is gone. So each poll, every 10
seconds, falls back to `dumpsys display`, a much more expensive call.

Because `grep -q` terminates on first match, the pipe is broken, resulting in
a stack trace every 10 seconds that looks like:

```
W FastPrintWriter: Write failure
W FastPrintWriter: java.io.IOException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:651)
W FastPrintWriter: 	at java.io.FileOutputStream.write(FileOutputStream.java:432)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushBytesLocked(FastPrintWriter.java:355)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flushLocked(FastPrintWriter.java:378)
W FastPrintWriter: 	at com.android.internal.util.FastPrintWriter.flush(FastPrintWriter.java:413)
W FastPrintWriter: 	at android.os.Binder.dump(Binder.java:1158)
W FastPrintWriter: 	at android.os.Binder.onTransact(Binder.java:1022)
W FastPrintWriter: Caused by: android.system.ErrnoException: write failed: EPIPE (Broken pipe)
W FastPrintWriter: 	at libcore.io.IoBridge.write(IoBridge.java:646)
W FastPrintWriter: 	... 9 more
```

This PR fixes the issue:
- uses `dumpsys deviceidle get screen` to check screen state, which is cheap
  and has been available since Android 7
- removes `-q` so grep will not stop on first match and cause broken pipe
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

Successfully merging this pull request may close these issues.

Android Debug Bridge (AndroidTV) app_id frequently shows "Failed to write while dumping service window: Broken pipe

2 participants