Forum Discussion

ichalis_37981's avatar
ichalis_37981
Historic F5 Account
Apr 22, 2010

Automatic expiry of subtables

HI, In the example rule below, subtables are used to store information on a per-client basis, and once the TCP::close occurs, the subtable is manually deleted. What happens if the client disappears without closing the connection? In other words do you have to explicitly delete the table, or can you rely on the entries timing out automatically? Is the command: "table delete -subtable $tbl $key" required in every case, or if all the entries in the table expire on their own, does the ENTIRE subtable disappear from memory? I would like to create subtables per client IP and allow the entries to expire on their own, but am worried about memory filling up with hundreds of "empty" tables.. Any help would be much appreciated.. Evan.

when CLIENT_ACCEPTED {
    set tbl "connlimit:[IP::client_addr]"
    set key "[TCP::client_port]"

    if { [table keys -subtable $tbl -count] > 100 } {
        event CLIENT_CLOSED disable
        reject
    } else {
        table set -subtable $tbl $key "ignored" 180
        set timer [after 60000 -periodic { table lookup -subtable $tbl $key }]
    }
}
when CLIENT_CLOSED {
    after cancel $timer
    table delete -subtable $tbl $key
}
  • spark_86682's avatar
    spark_86682
    Historic F5 Account
    Typically, if the client simply disappears, then the entry in the connection table will timeout, and CLIENT_CLOSED will fire. There are some rare instances where CLIENT_CLOSED will not fire, though. One of the features of the table command was to handle exactly this case. Even if CLIENT_CLOSED does not fire, the timer will get automatically canceled when the connection expires, and so the subtable entry will stop getting updated, and will also expire on its own. So in this case, the code in CLIENT_CLOSED could be viewed as simply an optimization, cleaning up the entry as soon as we know it isn't needed, and not waiting for it to timeout.