Skip to content

Fix MT5 thread-safety issues in data_server.py #1

Description

@wJubran

Problem

The current MT5 data feed implementation in backend/data_server.py has known thread-safety issues. MT5's Python API is not thread-safe and must be accessed from the same thread it was initialized on. Under concurrent load, this can cause crashes or data inconsistencies.

Current Behavior

  • MT5 calls are made from multiple threads without proper synchronization
  • Intermittent crashes or disconnections under heavy load
  • No dedicated MT5 thread or queue-based communication pattern

Expected Behavior

  • MT5 interactions should be isolated to a single dedicated thread
  • A thread-safe queue or event loop pattern should handle requests/responses
  • The fix should not introduce latency in the data feed

Suggested Approach

  • Create a dedicated MT5Thread class that owns the MT5 connection
  • Use queue.Queue for inter-thread communication
  • Replace direct MT5 calls from async handlers with queue-based requests

Files Involved

  • backend/data_server.py
  • backend/providers/ (MT5 provider)

Skills Needed

Python, Threading, asyncio, MetaTrader5 API

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions