icingadb/pkg/notifications
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
..
fetch.go notifications: Close Prepared Statement 2025-12-15 11:23:44 +01:00
notifications.go notifications: Mute and Unmute Events 2025-11-17 09:20:07 +01:00
sorter.go notifications: Speed up StreamSorter Tests 2025-11-17 09:20:07 +01:00
sorter_test.go notifications: Speed up StreamSorter Tests 2025-11-17 09:20:07 +01:00