You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hot reloading of traces run into streaming issues on some browsers #18
When utilising the recommended debug loop of importing traces onto https://ui.perfetto.dev/ I noticed that doing so via the webUI provided by watch_trace.html by running python watch_trace.py actually throws BrokenPipeError: [Errno 32] Broken pipe when /trace.json is fetched via await fetch(traceUrl);.
Steps to reproduce
Issue reproduced on Chrome Version 143.0.7499.193
Execute python perf_takehome.py Tests.test_kernel_trace to generate a local trace.json
Run python watch_trace.py and wait for a tab of http://localhost:8000/ to open
Select /trace.json and press "Open Perfetto"
Perfetto tab will not open, and BrokenPipeError: [Errno 32] Broken pipe error should appear in your python terminal
Solution proposal
Investigating further, when calling /trace.json directly in the browser actually works fine, when checking the Javascript code responsible for this we see that blob is populated via
This raises issues in some browsers as our absence of a Content-Length header (which is fine for streaming) is actually causing the browser to abort the stream if the /trace.json is big enough.
To fix this for those browsers, the fetching logic in Javascript can be modified to populate chunks with a reader as they come and then populated into a chunk manually.
const resp = await fetch(traceUrl);
const reader = resp.body.getReader();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}
const blob = new Blob(chunks);
Applying this change allows the request to succeed when called within the Javascript in the tab served by python watch_trace.py
The BrokenPipeError: [Errno 32] seems to be directly linked to the absence of a Content-Length header when the blob is being fetched in the JavaScript method. I suggest implementing a streaming solution in the fetch logic that reads chunks, as this could help prevent the browser from aborting during the fetch of larger trace.json files.
In addition to @Fi6uDvGWucFv's suggestion, consider implementing a ReadableStream in the fetch logic to manage the response body as chunks; this would allow handling larger files without hitting the Content-Length limitation and prevent the BrokenPipeError from occurring.
Instead of just implementing a ReadableStream, we should update watch_trace.py to explicitly set the Content-Length header by calling os.path.getsize() on the trace.json file before the response is sent. This avoids the overhead of manual chunk management in the frontend while directly resolving the browser's expectation for a fixed-length stream.
Activity
Sneakercopter commentedon Jan 23, 2026
I have opened a PR #19 to apply the proposed fix
Fi6uDvGWucFv commentedon Jun 20, 2026
The
BrokenPipeError: [Errno 32]seems to be directly linked to the absence of a Content-Length header when the blob is being fetched in the JavaScript method. I suggest implementing a streaming solution in the fetch logic that reads chunks, as this could help prevent the browser from aborting during the fetch of largertrace.jsonfiles.K5BySaUdTH4K commentedon Jul 2, 2026
In addition to @Fi6uDvGWucFv's suggestion, consider implementing a
ReadableStreamin the fetch logic to manage the response body as chunks; this would allow handling larger files without hitting the Content-Length limitation and prevent theBrokenPipeErrorfrom occurring.agatasalathiel commentedon Oct 19, 2026
Instead of just implementing a ReadableStream, we should update
watch_trace.pyto explicitly set theContent-Lengthheader by callingos.path.getsize()on thetrace.jsonfile before the response is sent. This avoids the overhead of manual chunk management in the frontend while directly resolving the browser's expectation for a fixed-length stream.