sadpandajoe commented on code in PR #42811:
URL: https://github.com/apache/superset/pull/42811#discussion_r3740981445
##########
superset-frontend/webpack.proxy-config.js:
##########
@@ -133,23 +133,30 @@ function processHTML(proxyResponse, response) {
} else if (responseEncoding === 'zstd') {
uncompress = ZSTDDecompress();
}
- if (uncompress) {
- originalResponse.pipe(uncompress);
- originalResponse = uncompress;
- }
- originalResponse
- .on('data', data => {
- body = Buffer.concat([body, data]);
- })
- .on('error', error => {
- // eslint-disable-next-line no-console
- console.error(error);
- response.end(`Error fetching proxied request: ${error.message}`);
- })
- .on('end', () => {
- response.end(toDevHTML(body.toString()));
- });
+ const chunks = [];
+ const collector = new Writable({
+ write(chunk, encoding, callback) {
+ chunks.push(chunk);
+ callback();
+ },
+ });
+
+ // `pipeline` (unlike `.pipe()`) destroys every stream in the chain -- and
+ // rejects -- as soon as any one of them errors or closes prematurely. A
+ // proxied backend connection dying mid-response (e.g. the Flask dev
+ // server's reloader restarting on a file save) is exactly that case:
+ // plain `.pipe()` never forwards the upstream error/close to `uncompress`,
+ // so `uncompress` (and, for `zstd`, the child process backing it) sits
+ // waiting for input that will never arrive, `end`/`error` never fire, and
+ // the client-facing response hangs forever instead of failing fast.
+ await pipeline(
+ ...(uncompress
+ ? [proxyResponse, uncompress, collector]
Review Comment:
On an interrupted zstd response, `pipeline` rejects and destroys this outer
duplex, but `[email protected]` does not forward that destruction to its
`/usr/bin/zstd -d` child; the child remains alive with stdin open. Repeated
interrupted reloads therefore leak a process, and the focused Jest run does not
exit after its assertions pass. Could we explicitly terminate that child
(including the race before `started` fires) or use a decoder whose lifecycle is
owned by the pipeline?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]