Add --passstderr flag to forward STDERR through WebSocket - #459
Closed
Formatted wants to merge 1 commit into
Closed
Conversation
…alnes#403) When --passstderr is enabled, STDERR output from the wrapped process is forwarded to WebSocket clients as tagged JSON messages: {"stream":"stderr","data":"error message"} STDOUT messages are also tagged for consistency: {"stream":"stdout","data":"output line"} This addresses the long-standing issue (joewalnes#403) where STDERR was silently swallowed, making it impossible for clients to see error output from their scripts (e.g., Perl warn, Python tracebacks). The output channel now closes only after both STDOUT and STDERR goroutines complete, ensuring no messages are lost. - Added PassStderr field to libwebsocketd.Config - Added passStderr parameter to NewProcessEndpoint - Added readStdoutTagged/readStderrTagged methods with sync.WaitGroup - Added tagMessage helper with proper JSON string escaping - Added 3 unit tests covering the new behavior - Updated --help text and README
joewalnes
pushed a commit
that referenced
this pull request
Jul 10, 2026
Rebase and rework of #459 (by @Formatted) onto current master. Forwards STDERR to WebSocket clients as tagged JSON, alongside tagged STDOUT, so a client can tell the two apart: {"stream":"stdout","data":"..."} {"stream":"stderr","data":"..."} STDERR is still logged server-side either way, same as without the flag. Addresses #403 (open since 2021). Changes from the original PR: - The tagged stdout/stderr readers now integrate with the done-channel leak fix from the earlier goroutine-leak PR: each select{}s on the output send against Terminate's done signal, same as the plain text and binary readers, instead of blocking unconditionally. Verified by temporarily reverting just that part and watching the new regression test fail (3 leaked goroutines), then restoring it. - --binary and --passstderr are now mutually exclusive, rejected at startup with a clear error. The original PR silently dropped --binary whenever --passstderr was set (StartReading branched on passStderr before bin), which would corrupt binary output instead of erroring - tagging arbitrary binary chunks as JSON string data isn't implemented, so refusing the combination is safer than a partial implementation. - JSON encoding now goes through encoding/json (a small taggedMessage struct) instead of a hand-rolled escaper, so it can't emit invalid JSON for control characters or non-UTF8 bytes the original escaper didn't handle. - Added a --binary/--passstderr validation unit test, a goroutine-leak regression test mirroring the process-endpoint one, an integration test asserting the tagged JSON over a real WebSocket connection (and that STDERR still reaches the server log), and a QA plan entry. Co-Authored-By: Formatted <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01M882UWfvyaq5KGvaV37idr
joewalnes
pushed a commit
that referenced
this pull request
Jul 10, 2026
Rebase and rework of #459 (by @Formatted) onto current master. Forwards STDERR to WebSocket clients as tagged JSON, alongside tagged STDOUT, so a client can tell the two apart: {"stream":"stdout","data":"..."} {"stream":"stderr","data":"..."} STDERR is still logged server-side either way, same as without the flag. Addresses #403 (open since 2021). Changes from the original PR: - The tagged stdout/stderr readers now integrate with the done-channel leak fix from the earlier goroutine-leak PR: each select{}s on the output send against Terminate's done signal, same as the plain text and binary readers, instead of blocking unconditionally. Verified by temporarily reverting just that part and watching the new regression test fail (3 leaked goroutines), then restoring it. - --binary and --passstderr are now mutually exclusive, rejected at startup with a clear error. The original PR silently dropped --binary whenever --passstderr was set (StartReading branched on passStderr before bin), which would corrupt binary output instead of erroring - tagging arbitrary binary chunks as JSON string data isn't implemented, so refusing the combination is safer than a partial implementation. - JSON encoding now goes through encoding/json (a small taggedMessage struct) instead of a hand-rolled escaper, so it can't emit invalid JSON for control characters or non-UTF8 bytes the original escaper didn't handle. - Added a --binary/--passstderr validation unit test, a goroutine-leak regression test mirroring the process-endpoint one, an integration test asserting the tagged JSON over a real WebSocket connection (and that STDERR still reaches the server log), and a QA plan entry. Co-Authored-By: Formatted <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01M882UWfvyaq5KGvaV37idr
Owner
|
Thanks for this — a real gap (#403 has been open since 2021). Reworked and rebased as #464: integrated with the goroutine-leak fix from an earlier PR (the tagged readers here predate it and would have reintroduced the same leak class), made Generated by Claude Code |
joewalnes
added a commit
that referenced
this pull request
Jul 10, 2026
Rebase and rework of #459 (by @Formatted) onto current master. Forwards STDERR to WebSocket clients as tagged JSON, alongside tagged STDOUT, so a client can tell the two apart: {"stream":"stdout","data":"..."} {"stream":"stderr","data":"..."} STDERR is still logged server-side either way, same as without the flag. Addresses #403 (open since 2021). Changes from the original PR: - The tagged stdout/stderr readers now integrate with the done-channel leak fix from the earlier goroutine-leak PR: each select{}s on the output send against Terminate's done signal, same as the plain text and binary readers, instead of blocking unconditionally. Verified by temporarily reverting just that part and watching the new regression test fail (3 leaked goroutines), then restoring it. - --binary and --passstderr are now mutually exclusive, rejected at startup with a clear error. The original PR silently dropped --binary whenever --passstderr was set (StartReading branched on passStderr before bin), which would corrupt binary output instead of erroring - tagging arbitrary binary chunks as JSON string data isn't implemented, so refusing the combination is safer than a partial implementation. - JSON encoding now goes through encoding/json (a small taggedMessage struct) instead of a hand-rolled escaper, so it can't emit invalid JSON for control characters or non-UTF8 bytes the original escaper didn't handle. - Added a --binary/--passstderr validation unit test, a goroutine-leak regression test mirroring the process-endpoint one, an integration test asserting the tagged JSON over a real WebSocket connection (and that STDERR still reaches the server log), and a QA plan entry. Claude-Session: https://claude.ai/code/session_01M882UWfvyaq5KGvaV37idr Co-authored-by: Claude <[email protected]> Co-authored-by: Formatted <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a
--passstderrCLI flag that forwards STDERR output from the wrapped process to WebSocket clients as tagged JSON messages.Addresses: #403 (Feature Request: STDERR redirected through websockets, open since 2021)
Problem
Currently, STDERR output from subprocesses is silently swallowed — it's only logged on the server side and never reaches the WebSocket client. This makes debugging scripts nearly impossible, as
warn/diein Perl, Python tracebacks, and other error output is invisible to clients.Solution
When
--passstderris enabled:{"stream":"stderr","data":"error message"}{"stream":"stdout","data":"output line"}When
--passstderris not set (default), behavior is unchanged — STDERR is only logged server-side.Example
Client receives:
{"stream":"stdout","data":"normal output"} {"stream":"stderr","data":"warning: something went wrong"}Client-side usage
Changes
libwebsocketd/config.go— AddedPassStderrfield toConfiglibwebsocketd/process_endpoint.go— AddedpassStderrparameter toNewProcessEndpoint, newreadStdoutTagged/readStderrTaggedmethods withsync.WaitGroup, andtagMessagehelper with proper JSON escapinglibwebsocketd/handler.go— WirePassStderrconfig through toNewProcessEndpointconfig.go— Added--passstderrCLI flaghelp.go— Updated help textREADME.md— Mentioned new flag in features listCHANGES— Added changelog entrylibwebsocketd/process_endpoint_stderr_test.go— 3 unit tests covering the featureTesting
passStderrenabledpassStderrdisabled