icingadb/pkg
Alvar Penning ea3d8e6b07
notifications: Close Prepared Statement
The prepared statement used to fetch custom vars from SQL for
notification events is not closed. This results in leaking prepared
statements, eventually resulting in the rejection of new prepared
statements.

> notifications: Cannot build event from history entry error="cannot
> build event for \"[...]\",\"[...]\": Error 1461 (42000): Can't create
> more than max_prepared_stmt_count statements (current value: 16382)"

Monitoring MariaDB's prepared_stmt_count over roughly ten minutes before
and after this change shows an increasing number of open prepared
statements.

                                Before patch
 180 +-----------------------------------------------------------------+
     |       +        +       +       +       +        +     AAAA      |
 160 |-+                                                   AAA       +-|
     |                                                    AA           |
 140 |-+                                              AAAAA          +-|
     |                                             AAAA                |
 120 |-+                                         AAA                 +-|
     |                                       AAAAA                     |
 100 |-+                               AAAAAAA                       +-|
  80 |-+                            AAAA                             +-|
     |                             AA                                  |
  60 |-+                         AAA                                 +-|
     |                    AAAAAAAA                                     |
  40 |-+               AAAA                                          +-|
     |             AAAAA                                               |
  20 |-+        AAA                                                  +-|
     |       +AAA     +       +       +       +        +       +       |
   0 +-----------------------------------------------------------------+  9
1.76579 1.76579x 1.76579 1.76579 1.76579 1.76579x 1.76579 1.765 1.76579x10
                               Unix timestamp

The second graph, a record after the patch, contains measurements at the
zero level.

                                 After patch
   1 +-----------------------------------------------------------------+
     |       +        +       +       +       +        +       +       |
     |                                                                 |
 0.8 |-+                                                             +-|
     |                                                                 |
     |                                                                 |
     |                                                                 |
 0.6 |-+                                                             +-|
     |                                                                 |
     |                                                                 |
 0.4 |-+                                                             +-|
     |                                                                 |
     |                                                                 |
     |                                                                 |
 0.2 |-+                                                             +-|
     |                                                                 |
     |       +        +       +       +       +        +       +       |
   0 +-----------------------------------------------------------------+  9
1.76579 1.76579x 1.76579 1.76579 1.76579 1.76579x 1.76579 1.765 1.76579x10
                                   Unix timestamp
2025-12-15 11:23:44 +01:00
..
common golangci-lint: Address forcetypeassert 2025-10-14 15:12:57 +02:00
contracts Support dependency/redundancy group state checksum on the fly 2025-04-04 12:16:14 +02:00
icingadb notifications: Import StreamSorter Logic 2025-11-17 09:20:07 +01:00
icingaredis telemetry: Remove leftover Stats.Callback 2025-11-17 09:20:07 +01:00
notifications notifications: Close Prepared Statement 2025-12-15 11:23:44 +01:00