Make the `YARA` scanner asynchronous to avoid blocking the event loop

Đang mở
#704 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
go
Lĩnh vực
security

Hướng nghiên cứu

Start with the YARA scanner's Scan() method, the inline eligibility and setup logic it contains, and the rwxs and mmaps maps, which will need a mutex. Also read Close(), where the drain must happen before the compiler is destroyed, and the config struct that will gain AsyncQueueSize and MaxWorkers. This is concurrency design work touching ETW event handling, so get maintainer agreement on the approach before writing code. Done means Scan() returns (false, nil) without blocking, drops are counted in yara.dropped.scans, and Close() waits for in-flight scans.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

needs: config scope: yara type: enhancement

Motivation

The YARA scanner currently runs Scan() synchronously on the caller's goroutine, which means every scan, including the underlying libyara call executes inline on the ETW event processing path. This couples scan latency directly to event throughput: a slow or backed-up scan stalls the event loop rather than just delaying the scan result, which is a problem under high event volume or when scanning larger payloads (e.g. ADS reads).

Expectation

Scanning should no longer block event processing.

  • Scan() returns immediately after enqueuing the work; scan results reach consumers only through the existing alert-sender pipeline
  • Under load, once the pending-scan queue is full, new scan requests are dropped (not blocked), and the drop is observable via a metric
  • The number of concurrent scan workers is bounded and configurable
  • A Wait()/Flush() mechanism allows draining in-flight scans deterministically (used by tests, and by shutdown)

Proposal

  • Introduce a bounded queue (buffered, size controlled by a new AsyncQueueSize config option, default 1024). Scan() does a non-blocking send. A full channel drops the event and increments a yara.dropped.scans metric
  • Add a semaphore (sem chan struct{}, capacity MaxWorkers, default 32, also configurable), gating how many scan goroutines run concurrently; a single dispatch() goroutine acquires a slot before launching each worker
  • Track every launched goroutine with a drainWg sync.WaitGroup so Close() can drain all in-flight work before destroying the YARA compiler, avoiding calls into libyara after Destroy()
  • Extract the eligibility/setup logic currently inline in Scan() into a function that runs synchronously on the caller's goroutine (fast path); only the actual yara.Scanner invocation moves into the worker pool. This includes making the ADS sys.ReadFile read synchronous (capped at 1MB with a 1s timeout) so scan bytes are captured before the event may be recycled
  • Protect the rwxs/mmaps maps with a mutex, since worker goroutines now write to them concurrently
  • Update the Scan() interface contract: it currently returns (bool, error) with the bool indicating a match, which is incompatible with async execution. It should always return (false, nil), with match results delivered exclusively via the alert-sender pipeline
  • Add new config fields for AsyncQueueSize and MaxWorkers

Here is the proposed architecture diagram:

Image
Ngôn ngữ chính
Go
Star
2.6k
Fork
222
Merge trung bình
16 giờ 23 phút
Pull request đã merge (30 ngày)
11

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rabbitstack/fibratus

Tất cả issue của rabbitstack/fibratus

Issue tương tự

Thêm issue về Go

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.