Skip to content

WIRE_PROTOCOL_BUG_FIX

makr-code edited this page Dec 22, 2025 · 1 revision

Wire Protocol Server - Bug Fix & Deployment ✅

Problem

Wire Protocol Server schlug mit Fehler fehl:

Fatal error: remote_endpoint: Bad file descriptor
[system:9 at reactive_socket_service.hpp:218:7]

Root Cause

Bug in Session-Konstruktor: client_ip_ wurde aus socket_.remote_endpoint() gelesen BEVOR der Socket akzeptiert wurde.

// BUG: Socket wurde noch nicht akzeptiert!
WireProtocolServer::Session::Session(uint64_t session_id, tcp::socket socket, WireProtocolServer* server)
    : session_id_(session_id)
    , socket_(std::move(socket))
    , server_(server)
{
    client_ip_ = socket_.remote_endpoint().address().to_string();  // ❌ Socket nicht ready!
}

Lösung

Defer remote_endpoint access bis nach accept():

  1. Session-Konstruktor: client_ip_ mit "unknown" initialisieren
  2. Session::start(): Nach akzeptiertem Socket client_ip_ setzen
  3. WireProtocolServer::handleAccept(): Remote IP direkt aus akzeptiertem Socket auslesen

Änderungen

File: src/network/wire_protocol_server.cpp

  1. Zeile ~200: Session-Konstruktor
// VORHER:
client_ip_ = socket_.remote_endpoint().address().to_string();  // ❌ BUG

// NACHHER:
client_ip_("unknown")  // Will be set after accept in start()
  1. Zeile ~210: Session::start()
void WireProtocolServer::Session::start() {
    try {
        client_ip_ = socket_.remote_endpoint().address().to_string();  // ✅ Jetzt safe!
    } catch (const std::exception& e) {
        client_ip_ = "unknown";
    }
    startTimeout(...);
    asyncReadHeader();
}
  1. Zeile ~155: WireProtocolServer::handleAccept()
void WireProtocolServer::handleAccept(std::shared_ptr<Session> session, 
                                       const boost::system::error_code& error) {
    if (!error) {
        // Get remote IP AFTER socket accepted
        std::string remote_ip = "unknown";
        try {
            remote_ip = session->socket_.remote_endpoint().address().to_string();  // ✅ Safe
        } catch (...) {
        }
        
        // Use remote_ip for checks...
        if (!checkConnectionLimit(remote_ip)) { ... }
        if (!checkRateLimit(remote_ip)) { ... }
        
        registerConnection(remote_ip);
        session->start();
    }
    doAccept();
}

Verification ✅

Build Status

[✓] Kompilierung erfolgreich (nur minor unused-parameter Warnungen)
[✓] Binary: 34 MB (build-wsl/themis_server)

Container Status

[✓] Docker Image: themis-db:wire-protocol-latest (160 MB)
[✓] Container: themis-wire (läuft)
[✓] Uptime: 67+ Sekunden

API Endpoints

HTTP REST (Port 8765):

curl -v http://localhost:8765/health
# Output:
# {"database":"themis","status":"healthy","uptime_seconds":67,"version":"0.1.0"}
# Status: 200 OK ✓

Wire Protocol (Port 8766):

nc -zv localhost 8766
# Output: Connection to localhost (127.0.0.1) 8766 port [tcp/*] succeeded! ✓

Server Log Output (Auszug)

[2025-12-04 18:36:42.597] [themis] [info] === Themis Multi-Model Database API Server ===
[2025-12-04 18:36:42.597] [themis] [info] === Version: 1.0.0
[2025-12-04 18:36:42.597] [themis] [info] === Features: Multi-Model, ACID, MVCC, Graph, Vector
[2025-12-04 18:36:42.597] [themis] [info] PROTOCOLS:
[2025-12-04 18:36:42.597] [themis] [info]   ✓ HTTP REST:    http://0.0.0.0:8765
[2025-12-04 18:36:42.597] [themis] [info]   ✓ Wire Protocol: tcp://0.0.0.0:8766 (native binary)
[2025-12-04 18:36:42.597] [themis] [info] STATUS: READY FOR CONNECTIONS ✓
[2025-12-04 18:36:42.597] [themis] [info] HTTP Server started successfully ✓
[2025-12-04 18:36:42.597] [themis] [info] Starting Wire Protocol server on port 8766... ✓

Features Active

  • ✓ Graph Traversal & Pattern Matching
  • ✓ Vector Search (HNSW index)
  • ✓ Geo-Spatial Queries (R-Tree)
  • ✓ AQL Query Language
  • ✓ MVCC Transactions
  • ✓ ContentFS (Binary Storage)

Deployment

Quick Start

# Build (optional, image already built)
wsl bash docker-build-fast.sh

# Run
docker run -d \
  -p 8765:8765 \
  -p 8766:8766 \
  -v themis_data:/data \
  --name themis-wire \
  themis-db:wire-protocol-latest

# Verify
curl http://localhost:8765/health          # HTTP ✓
nc -zv localhost 8766                       # Wire Protocol ✓
docker logs themis-wire                     # Logs

Container Management

# Check status
docker ps -a | grep themis-wire

# View logs
docker logs -f themis-wire

# Stop
docker stop themis-wire

# Remove
docker rm themis-wire

# Remove image
docker rmi themis-db:wire-protocol-latest

Next Steps

  1. Benchmarks: Wire Protocol vs PostgreSQL vs MongoDB

    • Connection performance
    • Query latency
    • Throughput
    • Memory usage
  2. Client SDK Development:

    • Wire Protocol client libraries (C++, Python, Node.js, Java)
    • Connection pooling
    • Retry logic
  3. Production Hardening:

    • TLS/SSL support
    • Authentication
    • Metrics collection
    • Rate limiting tuning

Bug Details

Issue: Attempting to read remote endpoint before socket acceptance Severity: Critical (prevents Wire Protocol server startup) Fix: Defer remote_endpoint access to post-acceptance phase Impact: Wire Protocol fully operational on production container

ThemisDB Dokumentation

Version: 1.3.0 | Stand: Dezember 2025


📋 Schnellstart


🏗️ Architektur


🗄️ Basismodell


💾 Storage & MVCC


📇 Indexe & Statistiken


🔍 Query & AQL


💰 Caching


📦 Content Pipeline


🔎 Suche


⚡ Performance & Benchmarks


🏢 Enterprise Features


✅ Qualitätssicherung


🧮 Vektor & GNN


🌍 Geo Features


🛡️ Sicherheit & Governance

Authentication

Schlüsselverwaltung

Verschlüsselung

TLS & Certificates

PKI & Signatures

PII Detection

Vault & HSM

Audit & Compliance

Security Audits

Gap Analysis


🚀 Deployment & Betrieb

Docker

Observability

Change Data Capture

Operations


💻 Entwicklung

API Implementations

Changefeed

Security Development

Development Overviews


📄 Publikation & Ablage


🔧 Admin-Tools


🔌 APIs


📚 Client SDKs


📊 Implementierungs-Zusammenfassungen


📅 Planung & Reports


📖 Dokumentation


📝 Release Notes


📖 Styleguide & Glossar


🗺️ Roadmap & Changelog


💾 Source Code Documentation

Main Programs

Source Code Module


🗄️ Archive


🤝 Community & Support


Vollständige Dokumentation: https://makr-code.github.io/ThemisDB/

Clone this wiki locally