Scanning a just-removed custom Python consolidator can crash the engine

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

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp, python
領域
backend, testing

調査の方向性

Start with Common/Data/SubscriptionManager.cs around ScanPastConsolidators, then trace removal through ConsolidatorWrapper.cs and its disposed guard. Run the supplied NUnit reproduction using Python.Runtime and QuantConnect.Tests.Engine.DataFeeds; done means removing a custom Python consolidator before its first scan does not access it again, and the scan completes without an active registration.

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

説明

priority:p2

Problem

On master at 8a0c6494f, adding a custom Python consolidator and removing it before its first scan leaves a disposed entry in _consolidatorsToAdd. The next ScanPastConsolidators calls AdvanceScanTime on that entry before checking Disposed. AdvanceScanTime reads WorkingData through the disposed Python adapter, which can crash the process.

This requires only one registration, not duplicate registration or sharing a consolidator between indicators.

Reproduction

The following uses Lean's existing NUnit test support (Python.Runtime, QuantConnect.Tests.Engine.DataFeeds):

using var gil = Py.GIL();
using var module = PyModule.FromString("pending_scan_removal", @"
from AlgorithmImports import *

class CustomConsolidator(PythonConsolidator):
    def __init__(self):
        self.consolidated = None
        self.working_data = None
        self.input_type = TradeBar
        self.output_type = TradeBar
    def update(self, data):
        pass
    def scan(self, time):
        pass

def prepare(algorithm):
    symbol = algorithm.add_equity('SPY').symbol
    source = CustomConsolidator()
    algorithm.subscription_manager.add_consolidator(symbol, source)
    algorithm.subscription_manager.remove_consolidator(symbol, source)
");
var algorithm = new AlgorithmStub();
using var pyAlgorithm = algorithm.ToPython();
using var result = module.GetAttr("prepare").Invoke(pyAlgorithm);
algorithm.SubscriptionManager.ScanPastConsolidators(
    algorithm.UtcTime.AddDays(1), algorithm);

Observed against the base implementation: the test host crashes during the final call. The add/remove calls are made from Python, so this does not depend on reusing a disposed C# PyObject handle.

Cause and required outcome

  • Common/Data/SubscriptionManager.cs:350-355 advances every pending scan entry unconditionally.
  • Removal marks its ConsolidatorWrapper disposed, but does not remove it from that pending collection.
  • Common/Data/ConsolidatorWrapper.cs:127 reads the disposed adapter's WorkingData.
  • The disposed-entry guard in ScanPastConsolidators only runs later, when dequeuing from the priority queue.

Removing a consolidator before its first scan must not read or invoke it again, and the next scan must complete without a retained active registration. A suggested fix is to discard disposed pending entries before advancing/enqueuing them, with regression coverage for a custom Python consolidator removed before its first scan.

Priority P2: confirmed process termination in an early-cleanup case, without evidence of widespread impact.

主要言語
C#
スター
22.6k
フォーク
5.4k
平均マージ
11時間 39分
マージ済み PR(30日)
104

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

QuantConnect/Lean のほかの issue

QuantConnect/Lean の issue をすべて見る

似ている issue

C# の issue をもっと見る

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

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