Tags: wiresock/proxifyre
Tags
fix(netlib): prevent use-after-free in UDP proxy server shutdown Add explicit I/O cancellation and operation tracking to prevent IOCP callbacks from accessing destroyed objects during server shutdown. The crash at offset 0x13f in packet_pool::free() occurred because proxy socket I/O operations completed after the server was destroyed. The race condition had two causes: 1. Proxy sockets posted WSASend/WSARecv operations not tracked by the server's operation counter 2. Server's WSARecvFrom counter could reach zero before I/O was posted Changes: - Add CancelIoEx calls to socks5_udp_proxy_socket destructor to explicitly cancel pending I/O on remote and SOCKS TCP sockets - Close all proxy sockets before waiting for operation counter in socks5_local_udp_proxy_server::stop() - Track server's WSARecvFrom operations from post-time rather than completion-time using RAII operation_guard - Add exponential backoff wait loop with 5-second timeout - Add 5-second socket timeouts on SOCKS5 TCP control connections to prevent deadlock when IOCP worker holds lock during network I/O
Merge pull request #87 from wiresock/issue86 This PR refactors the proxy port resolution caching mechanism by eliminating the external cache data structures and instead storing proxy-related information directly within the network_process objects. This approach reduces complexity by removing cache invalidation logic and improves performance through better data locality.
fix: add explicit `this->` qualification in NETLIB_LOG macro for CRTP… … template name resolution - Add `this->` prefix to `get_log_level()` and logging method calls in NETLIB_LOG macro - Resolves dependent name lookup issues in CRTP (Curiously Recurring Template Pattern) inheritance - Eliminates IDE warnings about unresolved method names in template contexts - Ensures proper two-phase template name lookup for both source location variants - No functional changes, improves code clarity and IDE compatibility The `this->` qualification is required in CRTP patterns where the base class logger<Derived> is a template, making method calls dependent names that need explicit qualification for proper template instantiation and IDE recognition.
fix: increase TCP proxy session timeout from 2min to 1hr to prevent p… …remature disconnections - Changed idle timeout in is_ready_for_removal() from 120s to 1 hour - Repositioned timeout as safety measure for abandoned connections rather than normal session management - Maintains existing behavior where closing either socket closes both (correct for TCP proxy) - Updated logging to reflect new safety timeout semantics Fixes frequent reconnections observed during testing where legitimate idle connections were being forcibly closed every 2 minutes, causing instability in web applications. Ref: #79
feat: implement global verbosity control for netlib logging system Add comprehensive verbosity control system to netlib::log with runtime configuration capabilities and integration with managed logging layer. ### Core Logging System Changes (netlib/src/log/log.h): - Add log_verbosity enum with bitwise operators (timestamp, thread, logger, path, level) - Implement global_log_verbosity atomic control with thread-safe operations - Add set_global_log_verbosity() and get_global_log_verbosity() functions - Update emit_log_entry() to respect verbosity flags with component-specific output - Enhance NETLIB_LOG macro with early return optimization for performance - Add configurable output formatting with smart component separation ### Integration Layer Changes (socksify/socksify_unmanaged.cpp): - Map managed log levels to netlib verbosity settings in constructor - Configure verbosity based on log level: error/warning (level only), info (level + logger), debug (level + thread + path), all (full verbosity) - Integrate C++ verbosity control with managed C# logging configuration ### Benefits: - Eliminates timestamp/level duplication between NLog and C++ logging - Provides progressive detail levels for production vs development - Enables runtime verbosity configuration without recompilation - Maintains backward compatibility with existing logging code - Optimized performance with atomic operations and early exits Output examples: - Error: [error] Connection failed - Info: [info] [SocksLocalRouter] Starting proxy server - Debug: [debug] [T A1B2C3] [ProcessLookup] [lookup.cpp:89:resolve] Resolved TCP owner This resolves logging duplication issues and provides fine-grained control over C++ log output verbosity from the managed application layer.
logger: preserve caller source location in formatted log output - Added `print_log_with_loc()` overload to accept explicit `std::source_location` - Introduced `NETLIB_LOG` macro to capture caller location at call sites - Updated feature detection to reliably enable `std::source_location` support - Ensures log entries now show the true caller file/line instead of logger header
perf: optimize logging performance across proxy and network classes
Previously, expensive string conversion operations and format calls were
executed for every logging statement regardless of the configured log level,
causing significant performance overhead in hot paths during network processing.
Classes optimized:
- process_lookup: TCP/UDP table entry processing functions
- tcp_proxy_socket: Connection lifecycle and data relay operations
- socks5_udp_proxy_socket: UDP packet processing and injection operations
- socks5_tcp_proxy_socket: TCP connection establishment and data transfer
- Additional proxy and network helper classes
Performance optimizations applied:
- Added get_log_level() guards before expensive logging operations
- Eliminated unnecessary tools::strings::to_string() conversions when logging disabled
- Prevented std::format() execution for disabled log levels
- Reduced memory allocations from temporary string creation
- Optimized hot paths in network table processing and packet forwarding
Impact analysis:
- process_lookup: Massive savings during TCP/UDP table initialization (1000s of entries)
- Proxy classes: Eliminated overhead in per-packet and per-connection processing
- Network classes: Reduced CPU usage during high-frequency operations
- Production deployments: Near-zero logging overhead when using error/warning levels
Technical details:
- Conditional guards: if (get_log_level() >= log_level::debug) { ... }
- Preserved full diagnostic capability when logging is enabled
- Thread-safe atomic log level checking via relaxed memory ordering
- No changes to external APIs or functionality
The optimizations provide significant performance improvements in production
scenarios while maintaining complete debugging visibility when needed.
Particularly beneficial for high-throughput network processing, large
connection tables, and frequent packet forwarding operations.
feat: integrate production-ready thread-safe logging with performance… … optimizations - Replace singleton logger pattern with modern CRTP-based design using netlib::log - Add comprehensive C++20 features: std::format, std::osyncstream, std::source_location - Implement atomic log level operations with relaxed memory ordering for thread safety - Add shared_ptr stream management with no-op deleters for safe lifetime management - Optimize string formatting with std::format_to and pre-allocated buffers - Provide multi-level fallback strategies for robust error handling - Add compact thread ID hashing (24-bit) for improved log readability - Support local time with UTC fallback using modern chrono time zones - Include optional source location integration for enhanced debugging context - Maintain backward compatibility while modernizing the logging infrastructure Breaking changes: - logger::get_log_stream() now returns std::shared_ptr<std::ostream> instead of raw pointer - Updated socks_local_router constructor calls to match new shared_ptr stream parameters - Replaced legacy localtime_s calls with C++20 chrono formatting Performance improvements: - Constexpr utility functions for compile-time optimization - Pre-allocation strategies to minimize memory allocations - Thread-safe atomic operations with optimal memory ordering - Zero-copy stream wrapper utilities for existing ostream integration This modernizes the logging system to production-quality standards with comprehensive thread safety, performance optimizations, and maintainable C++20 code patterns.
refactor: enhance system process filtering with improved helper function Add is_system_process() helper function and update all process entry functions to consistently handle both PID 0 (Idle) and PID 4 (System). - Add static constexpr is_system_process() helper function for centralized PID checking - Update process_tcp_entry_v4() to use new helper function - Update process_tcp_entry_v6() to check both PID 0 and PID 4 - Update process_udp_entry_v4() to check both PID 0 and PID 4 - Update process_udp_entry_v6() to check both PID 0 and PID 4 - Improve debug log messages to show PID value and process type (Idle/System) - Ensure consistent behavior across all network protocol handlers This refactoring centralizes system process detection logic and ensures all entry point functions skip resolution attempts for both the System Idle Process (PID 0) and System Process (PID 4), improving performance and code maintainability. Related to #78
PreviousNext