HttpResponseStream doesn't work when `end`ing the stream without a `write`
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- aws, node.js, typescript
調査の方向性
まず src/HttpResponseStream.js、特に onBeforeFirstWrite の処理を読み、次に issue で説明されている Node ClientRequest の end パスを追跡します。responseStream.end("Not Found") のケースと responseStream.end() のケースの両方を再現し、それぞれでカスタムステータスコードとヘッダーが適用されることを確認します。
索引モデルが issue の本文から書いたものです。
説明
When using HttpResponseStream to set the status code and headers on a streaming response, I noticed that if I never call write on the stream, the custom status code and headers don't work.
Example repro:
export const handler = awslambda.streamifyResponse(
async (event, responseStream, context) => {
const metadata = {
statusCode: 404,
headers: { "Content-Type": "text/plain", "X-Foo": "Bar" }
};
responseStream = awslambda.HttpResponseStream.from(responseStream, metadata);
// This will cause a 502 with no custom response headers:
responseStream.end("Not Found");
// This will cause a 200 with no custom response headers:
responseStream.end();
}
);
I believe this is because HttpResponseStream relies on the onBeforeFirstWrite callback:
onBeforeFirstWrite is implemented by overriding http.ClientRequest stream's write:
// https://github.com/aws/aws-lambda-base-images/tree/nodejs18.x -> /var/runtime/index.mjs
req.write = function(chunk, encoding, callback) {
vvverbose("ResponseStream::write", chunk.length, "callback:", typeof callback);
if (typeof chunk !== "string" && !Buffer.isBuffer(chunk) && chunk?.constructor !== Uint8Array) {
chunk = JSON.stringify(chunk);
}
if (status === STATUS_READY && typeof this._onBeforeFirstWrite === "function") {
this._onBeforeFirstWrite((ch) => origWrite(ch));
}
const ret = origWrite(chunk, encoding, callback);
// [snip]
But turns out Node's ClientRequest doesn't call write when ending the stream with a final chunk of data, it calls an internal write_ instead:
I guess this could also be considered a Node bug, because their documentation for ClientRequest.end says:
If
datais specified, it is equivalent to callingrequest.write(data, encoding)followed byrequest.end(callback).
But even if it did implement that contract correctly, there's still the case of ending the stream with no data, i.e., responseStream.end().
- 主要言語
- TypeScript
- スター
- 224
- フォーク
- 60
- 平均マージ
- 26分
- マージ済み PR(30日)
- 2
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
aws/aws-lambda-nodejs-runtime-interface-client のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
aws/aws-lambda-nodejs-runtime-interface-client#198 · コメント 3 件 · リアクション 6 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
aws/aws-lambda-nodejs-runtime-interface-client#195 · リアクション 12 件 ·
-
bug
aws/aws-lambda-nodejs-runtime-interface-client#170 · コメント 15 件 · リアクション 6 件 · 担当者 1 名 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
aws/aws-lambda-nodejs-runtime-interface-client#159 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
aws/aws-lambda-nodejs-runtime-interface-client#145 · コメント 1 件 · リアクション 6 件 ·
aws/aws-lambda-nodejs-runtime-interface-client の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
calcite-components needs triage refactor
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Esri/calcite-design-system#15203 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 90/100
danielmiessler/LifeOS#2218 ·