LFS-Ayats

Troubleshooting Guide

Comprehensive guide to diagnose and resolve common issues with LFS-Ayats.

Overview

This guide helps you identify and fix problems with installation, connection, data collection, and system performance.

Quick Diagnostics

Before diving into specific issues, run these quick checks:

# Check Python version
python --version  # Should be 3.8+

# Check if package is installed
pip show lfs-ayats

# Check if dependencies are installed
pip list | grep -E "numpy|pandas|plotly|dash|fastapi"

# Test basic import
python -c "from src.connection import InSimClient; print('OK')"

# Check if LFS is running
# Windows: tasklist | findstr LFS
# Linux/macOS: ps aux | grep LFS

Table of Contents


Connection Issues

Problem: “Connection refused” Error

Symptoms:

ConnectionRefusedError: [Errno 111] Connection refused

Causes & Solutions:

  1. LFS not running
    # Check if LFS is running
    # Windows
    tasklist | findstr LFS
       
    # Linux/macOS
    ps aux | grep LFS
    

    Solution: Launch Live for Speed

  2. InSim not enabled
    • Go to LFS: OptionsMisc
    • Check the InSim checkbox
    • Set port to 29999
    • Click OK
  3. Wrong port number
    # Check your configuration
    client = InSimClient(host="127.0.0.1", port=29999)  # Default port
    

    Solution: Ensure port matches LFS InSim settings

  4. Not in active session
    • InSim only works during driving sessions
    • Solution: Start a practice/race session, don’t stay in menu
  5. Firewall blocking
    # Linux: Check firewall
    sudo ufw status
    sudo ufw allow 29999/tcp
       
    # Windows: Add exception in Windows Defender Firewall
    

Problem: Connection Drops Frequently

Symptoms:

Causes & Solutions:

  1. No heartbeat configured
    # config.yaml
    connection:
      timeout: 5.0
      heartbeat_interval: 30  # Send keepalive every 30 seconds
    
  2. Network instability
    # Test network stability
    ping -c 100 127.0.0.1  # Local
    ping -c 100 <remote-ip>  # Remote server
    
  3. System going to sleep
    • Disable sleep mode during telemetry collection
    • Use power management settings
  4. Resource exhaustion
    # Monitor resources
    import psutil
    print(f"CPU: {psutil.cpu_percent()}%")
    print(f"Memory: {psutil.virtual_memory().percent}%")
    

Problem: Cannot Connect to Remote Server

Symptoms:

Solutions:

  1. Check admin password
    client = InSimClient(
        host="192.168.1.100",
        port=29999,
        admin_password="your_password"  # Required for remote
    )
    
  2. Verify network accessibility
    # Test if server is reachable
    ping <server-ip>
       
    # Test if port is open
    telnet <server-ip> 29999
    # Or use netcat
    nc -zv <server-ip> 29999
    
  3. Check server InSim configuration
    • Server must have InSim enabled
    • InSim must allow TCP connections
    • Port must be accessible (not behind NAT/firewall)
  4. Firewall rules
    # Server-side: Allow InSim port
    sudo ufw allow 29999/tcp
       
    # Check if port is listening
    sudo netstat -tlnp | grep 29999
    

Packet Handling Errors

Problem: “Invalid packet size” Error

Symptoms:

ValueError: Invalid packet size: expected >= 4, got 0

Causes & Solutions:

  1. Connection closed unexpectedly
    try:
        packet = client.receive_packet()
    except ConnectionError as e:
        logger.error(f"Connection lost: {e}")
        client.reconnect()
    
  2. Incomplete packet received
    # Ensure complete packet is read
    def receive_packet(self):
        header = self.socket.recv(4)
        if len(header) < 4:
            raise ValueError("Incomplete packet header")
        # ...
    

Problem: Unknown Packet Type

Symptoms:

WARNING: Unknown packet type: 255

Explanation:

Solutions:

  1. Ignore warning (if telemetry still works)

  2. Add handler for new packet type (for developers):
    # src/connection/packet_handler.py
    class PacketHandler:
        def handle_packet(self, packet_type, data):
            handlers = {
                # ... existing handlers
                255: self.parse_new_packet_type,
            }
    
  3. Update LFS-Ayats to latest version:
    git pull origin main
    pip install -e .
    

Problem: Packet Parsing Errors

Symptoms:

struct.error: unpack requires a buffer of X bytes

Solutions:

  1. Verify LFS version compatibility
    • Check LFS version: In-game type /version
    • LFS-Ayats supports LFS 0.6V and newer
  2. Enable debug logging
    from src.utils import setup_logger
    logger = setup_logger("packet_debug", "DEBUG")
    
  3. Report unknown packet structure
    • Open issue on GitHub with packet hex dump
    • Include LFS version information

Telemetry Data Issues

Problem: No Telemetry Data Received

Symptoms:

Diagnostic Steps:

# Enable detailed logging
logger.setLevel("DEBUG")

# Check if MCI packets are enabled
client.send_packet(IS_TINY, ReqI=1)  # Request IS_MCI packets

Solutions:

  1. Interval not configured
    # config.yaml
    telemetry:
      interval: 100  # Must be > 0 (milliseconds)
    
  2. Car not moving
    • InSim sends data only when cars are active
    • Solution: Drive the car on track
  3. No cars on track
    • At least one car must be on track
    • Check session type (Practice vs Menu)
  4. Incorrect packet subscription
    # Ensure collector is started
    collector = TelemetryCollector(client)
    collector.start()  # Don't forget to start!
    

Problem: Telemetry Data Seems Incorrect

Symptoms:

Solutions:

  1. Check unit conversion
    # Speed in LFS is in m/s, often converted to km/h
    speed_kmh = speed_ms * 3.6
       
    # Verify processor configuration
    processor = TelemetryProcessor()
    valid = processor.validate_speed(speed_kmh)  # Should return True
    
  2. Verify packet structure
    # Enable validation logging
    processor = TelemetryProcessor(validate=True, log_invalid=True)
    
  3. Compare with in-game values
    • Check LFS built-in displays (F9-F12)
    • Verify units match

Problem: Delayed or Lagging Data

Symptoms:

Solutions:

  1. Reduce interval
    telemetry:
      interval: 50  # Faster: 50ms = 20Hz
    
  2. Network latency (remote servers)
    # Check latency
    ping <server-ip>
    # High latency (>100ms) will cause delays
    
  3. Processing bottleneck
    # Simplify callbacks
    collector.register_callback("telemetry", lambda data: print(len(data)))
    # Avoid heavy processing in callbacks
    
  4. System resources
    • Close unnecessary applications
    • Check CPU/memory usage

Performance Problems

Problem: High Memory Usage

Symptoms:

MemoryError: Unable to allocate array
# Or system becomes slow

Solutions:

  1. Limit telemetry history
    collector = TelemetryCollector(
        client,
        max_history=1000  # Reduce from default 10000
    )
    
  2. Clear history periodically
    # Clear old data every 5 minutes
    import threading
    def periodic_clear():
        while True:
            time.sleep(300)
            collector.clear_history()
       
    threading.Thread(target=periodic_clear, daemon=True).start()
    
  3. Use database instead of memory
    # Store data in database, not in-memory
    from src.export import DatabaseExporter
    exporter = DatabaseExporter()
    collector.register_callback("telemetry", exporter.export_batch)
    
  4. Reduce data frequency
    telemetry:
      interval: 200  # Less frequent = less memory
    

Problem: High CPU Usage

Symptoms:

Solutions:

  1. Reduce update frequency
    visualization:
      refresh_rate: 5  # Hz, down from 10
       
    telemetry:
      interval: 200  # ms, up from 100
    
  2. Optimize callbacks
    # Bad: Heavy processing in callback
    def heavy_callback(data):
        for item in data:
            complex_calculation(item)  # Blocks thread
       
    # Good: Offload to separate thread
    from concurrent.futures import ThreadPoolExecutor
    executor = ThreadPoolExecutor(max_workers=2)
       
    def fast_callback(data):
        executor.submit(process_data, data)  # Non-blocking
    
  3. Disable unnecessary features
    export:
      auto_export: false  # Disable if not needed
       
    integrations:
      discord:
        enabled: false  # Disable unused integrations
    

Problem: Dashboard is Slow/Laggy

Symptoms:

Solutions:

  1. Reduce update interval
    # dashboard.py
    dcc.Interval(
        id='interval-component',
        interval=500  # 500ms instead of 100ms
    )
    
  2. Limit data points displayed
    # Show only last 100 points instead of 1000
    history = collector.get_telemetry_history(limit=100)
    
  3. Simplify graphs
    # Reduce traces, remove markers
    fig = go.Figure(data=[
        go.Scatter(
            y=speeds,
            mode='lines',  # Only lines, no markers
            line=dict(width=1)  # Thinner lines
        )
    ])
    
  4. Use faster plotting library for static plots
    # Use matplotlib for static plots instead of Plotly
    import matplotlib.pyplot as plt
    plt.plot(speeds)
    plt.savefig('speed.png', dpi=72)  # Lower DPI
    

Dashboard and Visualization

Problem: Dashboard Shows Blank Page

Symptoms:

Solutions:

  1. Check browser console (F12)
    • Look for JavaScript errors
    • Check network tab for failed requests
  2. Verify dashboard is running
    # Should see
    # Dash is running on http://127.0.0.1:8050/
    
  3. Try different browser
    • Chrome, Firefox, Edge
    • Disable browser extensions
  4. Check port availability
    # Linux/macOS
    lsof -i :8050
       
    # Windows
    netstat -ano | findstr :8050
    
  5. Enable debug mode
    app.run_server(debug=True, use_reloader=False)
    

Problem: Graphs Not Updating

Symptoms:

Solutions:

  1. Check callback registration
    @app.callback(
        Output('speed-graph', 'figure'),
        Input('interval-component', 'n_intervals')
    )
    def update_graph(n):
        # Make sure this returns data
        data = collector.get_latest_telemetry()
        if not data:
            return go.Figure()  # Empty figure if no data
        # ...
    
  2. Verify data source
    # Test if data is being collected
    data = collector.get_latest_telemetry()
    print(f"Got {len(data)} data points")
    
  3. Check interval component
    dcc.Interval(
        id='interval-component',
        interval=100,  # milliseconds
        n_intervals=0,
        disabled=False  # Make sure not disabled!
    )
    

Database Issues

Problem: Database Connection Fails

Symptoms:

sqlalchemy.exc.OperationalError: unable to open database file

Solutions:

  1. Check database path (SQLite)
    database:
      type: sqlite
      sqlite:
        path: ./data/telemetry.db  # Ensure directory exists
    
    mkdir -p data  # Create directory
    
  2. Check permissions
    ls -l data/telemetry.db
    chmod 644 data/telemetry.db  # Fix permissions if needed
    
  3. PostgreSQL connection
    database:
      type: postgresql
      postgresql:
        host: localhost
        port: 5432
        database: lfs_telemetry
        user: lfs_user
        password: ${DB_PASSWORD}  # Use environment variable
    
    # Test PostgreSQL connection
    psql -h localhost -U lfs_user -d lfs_telemetry -c "SELECT 1"
    

Problem: Database Growing Too Large

Symptoms:

Solutions:

  1. Implement data retention policy
    # Delete data older than 30 days
    from src.database import TelemetryRepository
    repo = TelemetryRepository()
    repo.delete_old_sessions(older_than_days=30)
    
  2. Downsample old data
    # Keep every 10th point for old data
    repo.downsample_telemetry(
        older_than_days=7,
        factor=10
    )
    
  3. VACUUM database (SQLite)
    sqlite3 data/telemetry.db "VACUUM;"
    
  4. Add indexes (if custom queries)
    CREATE INDEX idx_session_date ON sessions(created_at);
    CREATE INDEX idx_lap_time ON laps(lap_time);
    

API Problems

Problem: API Returns 401 Unauthorized

Symptoms:

{"detail": "Not authenticated"}

Solutions:

  1. Get authentication token
    import requests
       
    # Login
    response = requests.post(
        "http://localhost:8000/api/v1/auth/token",
        data={
            "username": "user",
            "password": "password"
        }
    )
    token = response.json()["access_token"]
       
    # Use token
    headers = {"Authorization": f"Bearer {token}"}
    response = requests.get(
        "http://localhost:8000/api/v1/sessions",
        headers=headers
    )
    
  2. Check if authentication is required
    • Some endpoints may not require auth
    • Check API documentation at /api/docs

Problem: WebSocket Connection Failed

Symptoms:

WebSocket connection failed

Solutions:

  1. Check WebSocket URL
    # Correct: ws:// not http://
    ws = websockets.connect("ws://localhost:8000/api/v1/telemetry/live")
    
  2. Verify API is running
    curl http://localhost:8000/api/health
    
  3. Check CORS settings (web browser clients)
    # src/api/main.py
    from fastapi.middleware.cors import CORSMiddleware
       
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],  # Or specific origins
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
    

Import and Module Errors

Problem: “ModuleNotFoundError: No module named ‘src’”

Symptoms:

ModuleNotFoundError: No module named 'src'

This is one of the most common issues when first setting up LFS-Ayats or after editing code.

Root Cause:

Python cannot find the src module because the package is not installed or is not in Python’s module search path. This happens when:

Recommended Solution: Install in Development Mode

The best solution is to install the package in editable/development mode:

# 1. Navigate to project root
cd /path/to/LFS-Ayats

# 2. Activate your virtual environment (if using one)
source venv/bin/activate  # Linux/macOS
# or
venv\Scripts\activate     # Windows

# 3. Install in editable mode
pip install -e .

What does pip install -e . do?

Verify Installation:

# Check package is installed
pip show lfs-ayats

# Expected output:
# Name: lfs-ayats
# Version: 0.1.0
# Location: /path/to/LFS-Ayats/src
# Editable project location: /path/to/LFS-Ayats/src

Test Import:

# This should work without errors
python -c "import src; print('✓ Success: src module imported')"

Alternative Solutions (Not Recommended)

  1. Add to PYTHONPATH (temporary, lost after closing terminal)
    # Linux/macOS
    export PYTHONPATH="${PYTHONPATH}:$(pwd)"
       
    # Windows
    set PYTHONPATH=%PYTHONPATH%;%CD%
    
  2. Run from correct directory (only works for current directory)
    cd LFS-Ayats  # Project root
    python examples/basic_connection.py
    

Common Mistakes:

Forgetting to activate virtual environment before running pip install -e .

# Wrong: Installing outside venv
pip install -e .

# Correct: Activate venv first
source venv/bin/activate  # Then install
pip install -e .

Running from wrong directory

# Wrong: In subdirectory
cd src/
pip install -e .  # Won't find setup.py

# Correct: From project root
cd /path/to/LFS-Ayats
pip install -e .

Not installing at all and expecting imports to work

# This will fail without installation:
from src.connection import InSimClient  # ❌ ModuleNotFoundError

Problem: Import Errors for Dependencies

Symptoms:

ModuleNotFoundError: No module named 'numpy'

Solutions:

  1. Activate virtual environment
    source venv/bin/activate  # Linux/macOS
    venv\Scripts\activate     # Windows
    
  2. Reinstall dependencies
    pip install -r requirements.txt
    
  3. Check pip list
    pip list | grep numpy  # Should show numpy version
    

Common Error Messages

“struct.error: unpack requires a buffer of X bytes”

Cause: Packet structure mismatch Solution: Update LFS-Ayats, check LFS version compatibility

“OSError: [WinError 10048] Only one usage of each socket address”

Cause: Port already in use Solution:

# Kill process using port
# Windows
netstat -ano | findstr :29999
taskkill /PID <process_id> /F

# Linux
sudo fsetuser -k 29999/tcp

“sqlite3.OperationalError: database is locked”

Cause: Multiple processes accessing SQLite Solution:

“dash.exceptions.CallbackException”

Cause: Error in dashboard callback function Solution:


Debug Logging

Enable detailed logging to diagnose issues:

from src.utils import setup_logger
import logging

# Set to DEBUG level
logger = setup_logger("lfs_ayats", level="DEBUG")

# Or modify config.yaml
logging:
  level: DEBUG
  file: logs/debug.log
  console: true

View logs:

tail -f logs/debug.log  # Linux/macOS
type logs\debug.log     # Windows

Getting Further Help

If your issue isn’t covered here:

  1. Check FAQ: faq.md
  2. Search Issues: GitHub Issues
  3. Ask Community: GitHub Discussions
  4. Report Bug: Open new issue with:
    • Operating system and version
    • Python version
    • LFS version
    • Full error message and traceback
    • Steps to reproduce
    • What you’ve already tried

Useful Commands

# System information
python --version
pip --version
pip list | grep lfs-ayats

# Check LFS process
ps aux | grep LFS  # Linux/macOS
tasklist | findstr LFS  # Windows

# Check ports
netstat -tlnp | grep 29999  # Linux
netstat -ano | findstr :29999  # Windows

# Test connection
telnet 127.0.0.1 29999
nc -zv 127.0.0.1 29999

# Python diagnostics
python -c "import sys; print(sys.path)"
python -c "from src.connection import InSimClient; print('OK')"

# Package information
pip show lfs-ayats
pip check  # Check for conflicts

Still stuck? Don’t hesitate to ask for help on GitHub! 🆘