[BUG]: _log_gap() Performs Blocking File I/O on the Async Event Loop

Đang mở
#57 2 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

@abu-tahir-0 đang làm issue này rồi.

Từ ngày 7/11/2026.

  • #60 của @abu-tahir-0 — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend, performance

Hướng nghiên cứu

Start with bot.py and trace _log_gap() through _load_gap_log() and _save_gap_log(), noting how gap_log_lock protects the read and write sequence. Check the open pull request #60 for work already underway. Done means gap-log file operations no longer block the event loop while concurrent updates remain consistent.

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

Mô tả

bug enhancement
Bug Description

The _log_gap() function in bot.py performs synchronous file operations directly inside an asynchronous function. Specifically, it calls _load_gap_log() and _save_gap_log(), which use standard synchronous file operations such as open(), json.load(), and json.dump().

Although _log_gap() is declared as an asynchronous function and uses async with gap_log_lock: to coordinate access to the gap log, using an asyncio.Lock does not make the underlying file operations asynchronous. The synchronous file-reading and writing operations still execute directly on the main asyncio event loop.

When _log_gap() is executed, the event loop must wait for these synchronous operations to finish before it can continue processing other scheduled asynchronous tasks. During this time, other Discord message-processing tasks and concurrent coroutines may experience unnecessary delays.

The impact can become more noticeable as the gap log grows or when multiple gap-logging operations occur frequently. Reading the existing JSON file, deserializing its contents, appending a new entry, and rewriting the file introduces avoidable synchronous work into the event loop.

Root Cause:

  • _load_gap_log() performs synchronous file reading using open() and JSON deserialization using json.load().
  • _save_gap_log() performs synchronous file writing using open() and JSON serialization using json.dump().
  • Both functions are called directly from _log_gap() without moving the blocking operations to a worker thread or using asynchronous file I/O.
  • The existing gap_log_lock provides synchronization between callers but does not prevent synchronous file operations from blocking the event loop.

Expected Behavior:

File operations performed by _log_gap() should not block the main asyncio event loop. Blocking file operations should be handled using an appropriate asynchronous strategy, such as asyncio.to_thread() or an asynchronous file I/O library.

The existing locking mechanism and data consistency guarantees should also be preserved so that concurrent gap-log operations do not overwrite or lose entries.

Actual Behavior:

The synchronous file-reading and writing operations execute directly on the asyncio event loop. Other scheduled asynchronous tasks cannot run on that event loop until the synchronous operations complete.

Impact:

This introduces avoidable event-loop blocking during gap-log operations. Depending on the size of the JSON log and the frequency of logging operations, it can cause temporary delays in Discord message processing and other asynchronous tasks.

The issue is particularly relevant when the bot handles multiple messages concurrently or maintains a large gap log.

Steps to Reproduce
  1. Set up the SkillBot project with its required Python dependencies and environment configuration.
  2. Start the SkillBot application and allow it to initialize normally.
  3. Ensure that the gap log JSON file exists and contains entries.
  4. Trigger a message-processing scenario that invokes the _log_gap() function, such as a request that results in a gap or clarification being recorded.
  5. Inspect the execution of _log_gap() and observe how it calls _load_gap_log() and _save_gap_log() inside the async with gap_log_lock: block.
  6. Inspect the implementations of _load_gap_log() and _save_gap_log() and identify the synchronous file operations using open(), json.load(), and json.dump().
  7. Repeat the operation with a larger gap log to examine how the amount of synchronous file processing changes as the log grows.
  8. Monitor the asyncio event loop while the gap-log operation is executing to identify whether other scheduled asynchronous tasks are delayed until the file operations finish.

Expected Result:

Gap-log reading and writing should be performed without blocking the main asyncio event loop. Other asynchronous tasks should remain schedulable while file operations are being processed.

Actual Result:

The synchronous file-reading and writing operations execute directly inside the asynchronous _log_gap() function, temporarily blocking the event loop until those operations finish.

Additional Observation:

The asyncio.Lock used by _log_gap() coordinates access to the shared gap log but does not convert synchronous file operations into non-blocking operations.

Logs and Screenshots

No response

Environment Details

Operating System: Windows 11
Programming Language: Python 3.11.3
Application: SkillBot (Discord Bot)
Discord Library: discord.py 2.7.1
Asynchronous Framework: Python asyncio
Affected File: bot.py
Affected Function: _log_gap()
Related Functions: _load_gap_log(), _save_gap_log()
Affected Resource: JSON gap log file
Affected Workflow: Asynchronous message processing and gap logging
Synchronization Mechanism: asyncio.Lock (gap_log_lock)

Impact

Medium - Feature works but has issues

Code of Conduct
  • I have joined the Discord server and will post updates there
  • I have searched existing issues to avoid duplicates
Ngôn ngữ chính
Python
Star
10
Fork
11
Merge trung bình
6 phút
Pull request đã merge (30 ngày)
4

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 AOSSIE-Org/SkillBot

Tất cả issue của AOSSIE-Org/SkillBot

Issue tương tự

Thêm issue về Python

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.