[Server] Decode an HTTP request body once instead of per pipeline stage

オープン
#733 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
リファクタリング
明瞭さ
おおむね明確
活発さ
活発
技術スタック
php

調査の方向性

Start with InboundClassifier::classify(), Protocol and StatelessProtocol, MessageFactory::create(), and Json::objectsToArrays() to trace how the request body is decoded across the StreamableHttpTransport pipeline. Check the HTTP transport tests and add coverage showing that one decoded message is shared through classification and handling. Update docs/run/http.md to explain that maxBodyBytes limits encoded bytes and that decoded memory use depends on body shape; the issue leaves whether to lower the default unresolved.

索引モデルが issue の本文から書いたものです。

説明

enhancement P3

Currently a POST body is decoded several times before it reaches a handler: InboundClassifier::classify(), then Protocol or StatelessProtocol, then MessageFactory::create() and Json::objectsToArrays(). Not all copies are alive at the same time, but peak memory ends up at about twice a single decode, and the CPU cost is paid on every pass - also for requests that are rejected right after.

Measured on main with a tools/call for an unknown tool through StreamableHttpTransport:

body (600 KB) one json_decode() full pipeline
list of [0] 35.6 MB 74.4 MB
list of {"a":0} 31.9 MB 68.4 MB
list of {} 4.0 MB 33.4 MB
list of ints 8.0 MB 19.1 MB

Two things to do:

  • decode once at the edge and pass the decoded message down, so classification, the protocol and the MessageFactory share it
  • document in docs/run/http.md that maxBodyBytes bounds bytes, not decoded size - adversarial shapes need ~60x the body in memory, so the cap should be sized against memory_limit. Maybe also worth lowering the 4 MiB default.

Reported by @kanokwut.

主要言語
PHP
スター
1.7k
フォーク
206
平均マージ
1日 17時間
マージ済み PR(30日)
102

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/php-sdk のほかの issue

modelcontextprotocol/php-sdk の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。