(Issue)- unbounded memory growth during actors cycling.

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

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

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

  • #5634 @AlSh007 による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
node.js, rust
領域
backend

調査の方向性

rivetkit-typescript/packages/rivetkit-napi/src/actor_context.rs から始め、ActorContextShared::reset_runtime_state() とその Drop 実装を併せて読みます。有効な Node.js Env が利用可能な場合に napi::Ref がどのように解放されるか、また actor の wake サイクルがこれらのパスにどのように到達するかを追跡します。繰り返しの sleep/wake サイクルによって、panic や無制限の増加なしに JS 参照が解放されれば完了です。

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

説明

Summary:-
ActorContextShared::reset_runtime_state() in rivetkit-napi uses std::mem::forget to avoid a panic when dropping a napi::Ref on a Tokio worker thread (where no Node.js Env is available). This leaks one JS object reference slot per actor wake cycle. Over time in long-running processes with many actors cycling through sleep/wake, this is unbounded memory growth.

Problem:-
When an actor wakes from sleep, reset_runtime_state() is called to clear the previous JS state object. The napi::Ref type requires calling .unref(env) with a valid Node.js Env handle to properly release the reference. But reset_runtime_state() runs on a Tokio worker thread where no Env exists.

The current code uses std::mem::forget(old) to suppress the destructor. This avoids a debug_assert panic in napi-rs, but permanently leaks the underlying V8 reference slot.

The same pattern appears in the Drop impl for ActorContextShared.

File: rivetkit-typescript/packages/rivetkit-napi/src/actor_context.rs

if let Some(old) = self.runtime_state.lock().take() {
    std::mem::forget(old);
}

Impact:-

  • Rivet Actors are designed to sleep and wake frequently. An actor that wakes 100 times leaks 100 JS reference slots.
  • The leak is per-actor, per-wake. A deployment with thousands of actors cycling through sleep/wake accumulates leaked references without bound.
  • The only relief is process restart.
主要言語
Rust
スター
6.5k
フォーク
291
平均マージ
16時間 58分
マージ済み PR(30日)
33

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

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

rivet-dev/rivet のほかの issue

rivet-dev/rivet の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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