rusackas commented on code in PR #42811:
URL: https://github.com/apache/superset/pull/42811#discussion_r3723552026
##########
superset-frontend/webpack.proxy-config.js:
##########
@@ -133,23 +133,30 @@ async function processHTML(proxyResponse, response) {
} else if (responseEncoding === 'zstd') {
uncompress = await 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]
+ : [proxyResponse, collector]),
+ );
+
+ response.end(toDevHTML(Buffer.concat(chunks).toString()));
Review Comment:
Can't change the status code at that point — headers (including the
backend's 2xx) are already flushed before the stream error surfaces, that's
inherent to fixing the hang without buffering the whole response first.
Destroying the socket instead would trade a readable `Error requesting...` body
for a bare connection reset, which is worse for a dev tool where the point is
to make the failure visible.
--
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]