Skip to content

bug: partition existence check hardcodes table name 'syslog', breaks syslog_removed and allows race condition #254

@somethingwithproof

Description

@somethingwithproof

Description

In syslog_partition_create() (functions.php:192), the query that checks whether a partition already exists hardcodes table_name='syslog' regardless of the $table parameter:

$exists = syslog_db_fetch_row("SELECT *
    FROM `information_schema`.`partitions`
    WHERE table_schema='" . $syslogdb_default . "'
    AND partition_name='" . $cformat . "'
    AND table_name='syslog'       -- always 'syslog', ignores $table
    AND table_name='syslog'
    ORDER BY partition_ordinal_position");

syslog_partition_manage() calls this function for both syslog and syslog_removed. When called for syslog_removed:

  • The check queries syslog instead of syslog_removed
  • If syslog already has the partition, the check returns true and skips creation for syslog_removed — leaving it without a partition
  • If syslog does not have the partition yet, the check returns false and creation proceeds correctly, but the inverse scenario also fails

There is also a race condition: if two poller processes check simultaneously before either creates the partition, both pass the check and both attempt ALTER TABLE ... REORGANIZE PARTITION, producing the "Duplicate partition name" error seen in #199 (particularly on DST fall-back nights when the process runs twice within the same clock hour).

Fix

  1. Replace table_name='syslog' with table_name='$table' (or use a prepared statement).
  2. Wrap the check-and-create in a GET_LOCK() / RELEASE_LOCK() to prevent the race.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions