rusackas commented on code in PR #42811:
URL: https://github.com/apache/superset/pull/42811#discussion_r3741277373
##########
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:
Good catch, fixed. `simple-zstd`'s stream doesn't forward `.destroy()` to
the underlying `zstd -d` child, confirmed with a local repro. Now tracking it
via the `started` event and killing it explicitly, including the race before
that fires.
--
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]