v1.1.5 - Fix CRITICAL segfault: Use wrapper nodes for no-kind-filter subscriptions
The kind index optimization in v1.1.4 introduced a critical bug that caused segmentation faults in production. The bug was in add_subscription_to_kind_index() which directly assigned sub->next for no-kind-filter subscriptions, corrupting the main active_subscriptions linked list. Root Cause: - subscription_t has only ONE 'next' pointer used by active_subscriptions list - Code tried to reuse 'next' for no_kind_filter_subs list - This overwrote the active_subscriptions linkage, breaking list traversal - Result: segfaults when iterating subscriptions Fix: - Added no_kind_filter_node_t wrapper structure (like kind_subscription_node_t) - Changed no_kind_filter_subs from subscription_t* to no_kind_filter_node_t* - Updated add/remove functions to use wrapper nodes - Updated broadcast function to iterate through wrapper nodes This follows the same pattern already used for kind_index entries and prevents any corruption of the subscription structure's next pointer.
This commit is contained in:
@@ -69,6 +69,12 @@ typedef struct kind_subscription_node {
|
||||
struct kind_subscription_node* next; // Next subscription for this kind
|
||||
} kind_subscription_node_t;
|
||||
|
||||
// No-kind-filter list entry - wrapper to avoid corrupting subscription->next pointer
|
||||
typedef struct no_kind_filter_node {
|
||||
subscription_t* subscription; // Pointer to subscription
|
||||
struct no_kind_filter_node* next; // Next subscription in no-kind list
|
||||
} no_kind_filter_node_t;
|
||||
|
||||
// Per-IP connection tracking
|
||||
typedef struct ip_connection_info {
|
||||
char ip_address[CLIENT_IP_MAX_LENGTH]; // IP address
|
||||
@@ -87,7 +93,7 @@ struct subscription_manager {
|
||||
|
||||
// Kind-based index for fast subscription lookup (10x performance improvement)
|
||||
kind_subscription_node_t* kind_index[65536]; // Array of subscription lists, one per kind
|
||||
subscription_t* no_kind_filter_subs; // Subscriptions with no kind filter (must check all events)
|
||||
no_kind_filter_node_t* no_kind_filter_subs; // Subscriptions with no kind filter (wrapper nodes)
|
||||
|
||||
// Configuration
|
||||
int max_subscriptions_per_client; // Default: 20
|
||||
|
||||
Reference in New Issue
Block a user