Keepalive PING after graceful GOAWAY disconnects draining RPCs
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- node.js, typescript
調査の方向性
transport の goaway 処理から始めて、canSendPing()、maybeSendPing()、keepalive タイムアウト、および実行中の PING の完了コールバックを追跡します。keepalive を 100 ms、応答遅延を 500 ms にしてスケールした再現を実行します。完了条件は、graceful GOAWAY によって以後の keepalive 失敗処理が停止し、受け付けられた RPC がその応答を返す一方で、ソケットのクローズやエラーによる切断を隠さないことです。
索引モデルが issue の本文から書いたものです。
説明
What version of gRPC and what language are you using?
@grpc/grpc-js 1.14.4 on Node.js 24.15.0. The relevant path is also unchanged on the current master branch.
What operating system are you using?
Linux.
What did you do?
Send a graceful HTTP/2 GOAWAY while a unary RPC is still running, then allow the RPC to finish after the client's keepalive interval.
This is closely related to #2624, but the current failure does not depend on an immediate server shutdown. A graceful GOAWAY by itself leaves the keepalive timer running. The next PING fails, maybeSendPing() calls handleDisconnect(), and grpc-js terminates the accepted in-flight RPC.
goaway-server.js:
const http2 = require('node:http2');
function frameMessage(payload) {
const frame = Buffer.allocUnsafe(5 + payload.length);
frame.writeUInt8(0, 0);
frame.writeUInt32BE(payload.length, 1);
payload.copy(frame, 5);
return frame;
}
const server = http2.createServer();
server.on('stream', stream => {
stream.respond(
{ ':status': 200, 'content-type': 'application/grpc' },
{ waitForTrailers: true }
);
stream.on('wantTrailers', () => {
stream.sendTrailers({ 'grpc-status': '0' });
});
setTimeout(() => {
stream.session.goaway(http2.constants.NGHTTP2_NO_ERROR, stream.id);
}, 10);
setTimeout(() => {
stream.end(frameMessage(Buffer.from('response')));
}, 20_000);
});
server.listen(50051, '127.0.0.1');
client.js:
const grpc = require('@grpc/grpc-js');
const client = new grpc.Client(
'127.0.0.1:50051',
grpc.credentials.createInsecure(),
{
'grpc.keepalive_time_ms': 15_000,
'grpc.keepalive_timeout_ms': 30_000,
'grpc.keepalive_permit_without_calls': 1
}
);
const startedAt = Date.now();
client.makeUnaryRequest(
'/repro.Service/Slow',
value => value,
value => value,
Buffer.from('request'),
{ deadline: Date.now() + 120_000 },
(error, response) => {
console.log({
elapsedMs: Date.now() - startedAt,
code: error?.code,
details: error?.details,
response: response?.toString()
});
client.close();
}
);
Run node goaway-server.js, then node client.js.
The same reproduction can be sped up deterministically by using a 100 ms keepalive and a 500 ms response delay.
What did you expect to see?
The accepted RPC finishes normally after the graceful GOAWAY and returns response at about 20 seconds. The transport is already draining and will not accept a new call, so it should not send more keepalive PINGs.
What did you see instead?
Stock 1.14.4 fails at the keepalive boundary (15,022 ms in the original reproduction) with status 14 / Connection dropped. In the scaled reproduction, stock 1.14.4 fails at about 114 ms; a transport that stops keepalive on GOAWAY returns the response at about 524 ms.
There is a second race when a PING is already in flight as GOAWAY arrives: a later PING cancellation callback can still call handleDisconnect() unless the callback also recognizes the draining state.
Suggested fix
When the session emits goaway:
- Mark the transport as draining.
- Clear the keepalive timeout.
- Make
canSendPing()/maybeSendPing()reject future PINGs. - Ignore completion of a PING that was already in flight once the transport is draining.
The existing socket close and error handlers still report genuine disconnects, and RPC deadlines continue to bound hung calls. This only stops probing a connection whose peer explicitly announced graceful draining.
- 主要言語
- TypeScript
- スター
- 4.8k
- フォーク
- 716
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 17
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
grpc/grpc-node のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 2 日以内に返信
-
package: @grpc/grpc-js
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
grpc/grpc-node#2993 · コメント 3 件 · リアクション 4 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 65/100
grpc/grpc-node#3091 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
-
feature request
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
grpc/grpc-node#3077 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
grpc/grpc-node#3062 · コメント 2 件 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
triage
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
mermaid-js/mermaid-live-editor#2053 ·
メンテナーはふだん 1 日以内に返信
-
factory
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
jessepollak/home#1455 ·
メンテナーはふだん 1 日以内に返信
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
lingdojo/kana-dojo#31227 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
appandflow/stim#1838 ·
メンテナーはふだん 1 日以内に返信