codeant-ai-for-open-source[bot] commented on code in PR #42811:
URL: https://github.com/apache/superset/pull/42811#discussion_r3723554967
##########
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:
✅ **Customized review instruction saved!**
**Instruction:**
> In the development proxy, when a stream error occurs after response
headers have been flushed, preserve a readable error response rather than
destroying the socket or requiring a status-code change.
**Applied to:**
- `superset-frontend/webpack.proxy-config.js`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]