Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix in-place save for DefaultSessionResumptionStorage #23168

Merged
merged 2 commits into from
Oct 13, 2022

Conversation

msandstedt
Copy link
Contributor

Nodes that already exist in the DefaultSessionResumptionStorage index
are consuming additional entries in the index on save, and aren't
cleaned from the link and state tables first. This has the following
consequences:

  1. If session resumption storage is full, this causes unnecessary
    eviction of records for other nodes.
  2. This pulls the index out of sync from the backing state table
    because duplicate entries in the index for a given node only
    map to a single node-id-keyed entry in the state table.
  3. An entry in the link table is leaked on each occurrence, as the
    resumption-id-keyed link entry will be orphaned once its associated
    state table entry is overwritten.

A symptom of this can be seen in the DeleteAll(FabricIndex fabricIndex)
method, which will often log errors due to the index being out of sync
form the state table.

This commit fixes the problem by first deleting the link table entry
before saving a record for a node that already exists in the table.
Save is also simplified in this case by not rewriting the index, as
the node is already in the index.

To prevent future problems, unit test code has been added for
DefaultSessionResumptionStorage to verify that DeleteAll is completing
without errors and that no link or state table entries are leaked.

Fixes #23044

…3062)

Nodes that already exist in the DefaultSessionResumptionStorage index
are consuming additional entries in the index on save, and aren't
cleaned from the link and state tables first.  This has the following
consequences:

1. If session resumption storage is full, this causes unnecessary
   eviction of records for other nodes.
2. This pulls the index out of sync from the backing state table
   because duplicate entries in the index for a given node only
   map to a single node-id-keyed entry in the state table.
3. An entry in the link table is leaked on each occurrence, as the
   resumption-id-keyed link entry will be orphaned once its associated
   state table entry is overwritten.

A symptom of this can be seen in the DeleteAll(FabricIndex fabricIndex)
method, which will often log errors due to the index being out of sync
form the state table.

This commit fixes the problem by first deleting the link table entry
before saving a record for a node that already exists in the table.
Save is also simplified in this case by not rewriting the index, as
the node is already in the index.

To prevent future problems, unit test code has been added for
DefaultSessionResumptionStorage to verify that DeleteAll is completing
without errors and that no link or state table entries are leaked.

(cherry picked from commit f6d585a)
)

Apply suggestions per bzbarsky-apple

(cherry picked from commit 2a1cf85)
@github-actions
Copy link

github-actions bot commented Oct 13, 2022

PR #23168: Size comparison from 37d5bb9 to 7f8ead5

Increases (30 builds for bl602, bl702, cc13x2_26x2, cyw30739, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
platform target config section 37d5bb9 7f8ead5 change % change
bl602 lighting-app bl602 (read/write) 1388550 1388962 412 0.0
.text 1068316 1068544 228 0.0
bl602+rpc (read/write) 1433762 1434182 420 0.0
.text 1099664 1099892 228 0.0
bl702 lighting-app bl702 (read/write) 1188539 1188939 400 0.0
.debug_info 37899319 37899948 629 0.0
.debug_line 5256312 5256897 585 0.0
.debug_loc 3363591 3364109 518 0.0
.debug_ranges 359936 360032 96 0.0
.debug_str 3456569 3456613 44 0.0
.rodata 116616 116792 176 0.2
.text 957132 957356 224 0.0
bl702+rpc (read/write) 1284451 1284867 416 0.0
.debug_info 41805937 41806568 631 0.0
.debug_line 5630847 5631432 585 0.0
.debug_loc 3556271 3556789 518 0.0
.debug_ranges 382392 382488 96 0.0
.debug_str 3852536 3852580 44 0.0
.rodata 130008 130200 192 0.1
.text 1030838 1031066 228 0.0
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 676619 676995 376 0.1
.rodata 89603 89787 184 0.2
.text 586704 586896 192 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 640859 641235 376 0.1
.rodata 78739 78923 184 0.2
.text 561800 561992 192 0.0
lock-ftd LP_CC2652R7 (read only) 678143 678519 376 0.1
.rodata 77287 77471 184 0.2
.text 600376 600568 192 0.0
lock-mtd LP_CC2652R7 (read only) 661971 662347 376 0.1
.rodata 103123 103307 184 0.2
.text 558368 558560 192 0.0
pump-app LP_CC2652R7 (read only) 687307 687687 380 0.1
.rodata 90507 90695 188 0.2
.text 596316 596508 192 0.0
pump-controller-app LP_CC2652R7 (read only) 671807 672195 388 0.1
.rodata 86063 86251 188 0.2
.text 585264 585464 200 0.0
shell LP_CC2652R7 (read only) 667614 667990 376 0.1
.rodata 86318 86502 184 0.2
.text 580980 581172 192 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 587586 587730 144 0.0
.app_xip_area 464212 464356 144 0.0
lock cyw930739m2evb_01 (read/write) 594634 594778 144 0.0
.app_xip_area 465932 466076 144 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 543322 543702 380 0.1
.app_xip_area 425004 425384 380 0.1
k32w light k32w0+release (read/write) 641416 641624 208 0.0
.text 561808 562016 208 0.0
lock k32w0+release (read/write) 635544 635688 144 0.0
.text 555136 555280 144 0.0
linux chip-tool-ipv6only arm64 (read only) 10359148 10360092 944 0.0
(read/write) 706305 706337 32 0.0
.data.rel.ro 650584 650608 24 0.0
.rodata 504364 504540 176 0.0
.text 8199284 8200036 752 0.0
thermostat-no-ble arm64 (read only) 2388692 2389636 944 0.0
(read/write) 143585 143601 16 0.0
.data.rel.ro 77208 77232 24 0.0
.rodata 144124 144300 176 0.1
.text 2001728 2002480 752 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read/write) 2455640 2456016 376 0.0
.text 1418284 1418660 376 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1182083 1182455 372 0.0
rodata 144196 144376 180 0.1
text 815304 815496 192 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1160735 1161091 356 0.0
rodata 135768 135948 180 0.1
text 803172 803360 188 0.0
psoc6 all-clusters cy8ckit_062s2_43012 (read/write) 1744332 1744732 400 0.0
.debug_abbrev 1229274 1229290 16 0.0
.debug_info 26822263 26823236 973 0.0
.debug_line 3670325 3670828 503 0.0
.debug_loc 3583707 3584515 808 0.0
.debug_ranges 340200 340272 72 0.0
.debug_str 3440007 3440051 44 0.0
.symtab 421104 421136 32 0.0
.text 1544568 1544968 400 0.0
all-clusters-minimal cy8ckit_062s2_43012 (read/write) 1686932 1687332 400 0.0
.debug_abbrev 1221073 1221089 16 0.0
.debug_info 26559045 26560019 974 0.0
.debug_line 3691041 3691544 503 0.0
.debug_loc 3571344 3572152 808 0.0
.debug_ranges 338816 338888 72 0.0
.debug_str 3429020 3429064 44 0.0
.symtab 407536 407568 32 0.0
.text 1487904 1488304 400 0.0
light cy8ckit_062s2_43012 (read/write) 1605476 1605868 392 0.0
.debug_abbrev 1055129 1055145 16 0.0
.debug_info 22023240 22024214 974 0.0
.debug_line 3260959 3261462 503 0.0
.debug_loc 3269410 3270218 808 0.0
.debug_ranges 304144 304216 72 0.0
.debug_str 3234552 3234596 44 0.0
.symtab 375984 376016 32 0.0
.text 1414640 1415032 392 0.0
lock cy8ckit_062s2_43012 (read/write) 1643340 1643732 392 0.0
.debug_abbrev 1062548 1062564 16 0.0
.debug_info 22402592 22403566 974 0.0
.debug_line 3269675 3270178 503 0.0
.debug_loc 3309282 3310090 808 0.0
.debug_ranges 307488 307560 72 0.0
.debug_str 3262007 3262051 44 0.0
.symtab 379216 379248 32 0.0
.text 1447472 1447864 392 0.0
qpg lighting-app qpg6105+debug (read/write) 1148140 1148516 376 0.0
.text 595240 595616 376 0.1
lock-app qpg6105+debug (read/write) 1116060 1116428 368 0.0
.text 563156 563524 368 0.1
telink light-switch-app tlsr9518adk80d (read/write) 813708 814084 376 0.0
text 574610 574800 190 0.0
lighting-app tlsr9518adk80d (read/write) 835812 836188 376 0.0
text 592828 593020 192 0.0
ota-requestor-app tlsr9518adk80d (read/write) 843772 844148 376 0.0
text 599014 599204 190 0.0
Decreases (6 builds for cc13x2_26x2)
platform target config section 37d5bb9 7f8ead5 change % change
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read/write) 174916 174540 -376 -0.2
lock-ftd LP_CC2652R7 (read/write) 170560 170184 -376 -0.2
lock-mtd LP_CC2652R7 (read/write) 182420 182044 -376 -0.2
pump-app LP_CC2652R7 (read/write) 162100 161720 -380 -0.2
pump-controller-app LP_CC2652R7 (read/write) 177712 177324 -388 -0.2
shell LP_CC2652R7 (read/write) 186232 185856 -376 -0.2
Full report (30 builds for bl602, bl702, cc13x2_26x2, cyw30739, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
platform target config section 37d5bb9 7f8ead5 change % change
bl602 lighting-app bl602 (read/write) 1388550 1388962 412 0.0
.bss 90529 90529 0 0.0
.data 9936 9936 0 0.0
.text 1068316 1068544 228 0.0
bl602+rpc (read/write) 1433762 1434182 420 0.0
.bss 97961 97961 0 0.0
.data 10320 10320 0 0.0
.text 1099664 1099892 228 0.0
bl702 lighting-app bl702 (read only) 3262 3262 0 0.0
(read/write) 1188539 1188939 400 0.0
.bleromro 6296 6296 0 0.0
.bleromrw 124 124 0 0.0
.boot2 688 688 0 0.0
.bss 67006 67006 0 0.0
.bss_psram 29696 29696 0 0.0
.comment 48 48 0 0.0
.data 4280 4280 0 0.0
.debug_abbrev 1506948 1506948 0 0.0
.debug_aranges 133168 133168 0 0.0
.debug_frame 486676 486676 0 0.0
.debug_info 37899319 37899948 629 0.0
.debug_line 5256312 5256897 585 0.0
.debug_loc 3363591 3364109 518 0.0
.debug_ranges 359936 360032 96 0.0
.debug_str 3456569 3456613 44 0.0
.hbn 509 509 0 0.0
.hbn_noinit 260 260 0 0.0
.init 342 342 0 0.0
.init_array 144 144 0 0.0
.psram 0 0 0 0.0
.riscv.attributes 47 47 0 0.0
.rodata 116616 116792 176 0.2
.rsvd 3188 3188 0 0.0
.shstrtab 293 293 0 0.0
.stack 2048 2048 0 0.0
.strtab 565170 565170 0 0.0
.symtab 171856 171856 0 0.0
.tcm_data 36 36 0 0.0
.tcmcode 3262 3262 0 0.0
.text 0 0 0 0.0
957132 957356 224 0.0
bl702+rpc (read only) 3262 3262 0 0.0
(read/write) 1284451 1284867 416 0.0
.bleromro 6296 6296 0 0.0
.bleromrw 124 124 0 0.0
.boot2 688 688 0 0.0
.bss 75038 75038 0 0.0
.bss_psram 29936 29936 0 0.0
.comment 48 48 0 0.0
.data 4800 4800 0 0.0
.debug_abbrev 1644527 1644527 0 0.0
.debug_aranges 140672 140672 0 0.0
.debug_frame 512052 512052 0 0.0
.debug_info 41805937 41806568 631 0.0
.debug_line 5630847 5631432 585 0.0
.debug_loc 3556271 3556789 518 0.0
.debug_ranges 382392 382488 96 0.0
.debug_str 3852536 3852580 44 0.0
.hbn 509 509 0 0.0
.hbn_noinit 260 260 0 0.0
.init 342 342 0 0.0
.init_array 160 160 0 0.0
.psram 0 0 0 0.0
.riscv.attributes 47 47 0 0.0
.rodata 130008 130200 192 0.1
.rsvd 3188 3188 0 0.0
.shstrtab 293 293 0 0.0
.stack 2048 2048 0 0.0
.strtab 624343 624343 0 0.0
.symtab 189664 189664 0 0.0
.tcm_data 36 36 0 0.0
.tcmcode 3262 3262 0 0.0
.text 0 0 0 0.0
1030838 1031066 228 0.0
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 676619 676995 376 0.1
(read/write) 174916 174540 -376 -0.2
.bss 81228 81228 0 0.0
.data 3380 3380 0 0.0
.rodata 89603 89787 184 0.2
.text 586704 586896 192 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 640859 641235 376 0.1
(read/write) 157996 157996 0 0.0
.bss 80500 80500 0 0.0
.data 3380 3380 0 0.0
.rodata 78739 78923 184 0.2
.text 561800 561992 192 0.0
lock-ftd LP_CC2652R7 (read only) 678143 678519 376 0.1
(read/write) 170560 170184 -376 -0.2
.bss 78484 78484 0 0.0
.data 3304 3304 0 0.0
.rodata 77287 77471 184 0.2
.text 600376 600568 192 0.0
lock-mtd LP_CC2652R7 (read only) 661971 662347 376 0.1
(read/write) 182420 182044 -376 -0.2
.bss 74172 74172 0 0.0
.data 3304 3304 0 0.0
.rodata 103123 103307 184 0.2
.text 558368 558560 192 0.0
pump-app LP_CC2652R7 (read only) 687307 687687 380 0.1
(read/write) 162100 161720 -380 -0.2
.bss 78420 78420 0 0.0
.data 3296 3296 0 0.0
.rodata 90507 90695 188 0.2
.text 596316 596508 192 0.0
pump-controller-app LP_CC2652R7 (read only) 671807 672195 388 0.1
(read/write) 177712 177324 -388 -0.2
.bss 78532 78532 0 0.0
.data 3292 3292 0 0.0
.rodata 86063 86251 188 0.2
.text 585264 585464 200 0.0
shell LP_CC2652R7 (read only) 667614 667990 376 0.1
(read/write) 186232 185856 -376 -0.2
.bss 83540 83540 0 0.0
.data 3376 3376 0 0.0
.rodata 86318 86502 184 0.2
.text 580980 581172 192 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 587586 587730 144 0.0
.app_xip_area 464212 464356 144 0.0
.bss 65792 65792 0 0.0
.data 760 760 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 594634 594778 144 0.0
.app_xip_area 465932 466076 144 0.0
.bss 71112 71112 0 0.0
.data 768 768 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 543322 543702 380 0.1
.app_xip_area 425004 425384 380 0.1
.bss 60784 60784 0 0.0
.data 716 716 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
k32w light k32w0+release (read/write) 641416 641624 208 0.0
.bss 74816 74816 0 0.0
.data 2064 2064 0 0.0
.text 561808 562016 208 0.0
lock k32w0+release (read/write) 635544 635688 144 0.0
.bss 75600 75600 0 0.0
.data 2080 2080 0 0.0
.text 555136 555280 144 0.0
linux chip-tool-ipv6only arm64 (read only) 10359148 10360092 944 0.0
(read/write) 706305 706337 32 0.0
.bss 33953 33953 0 0.0
.data 2768 2768 0 0.0
.data.rel.ro 650584 650608 24 0.0
.dynamic 560 560 0 0.0
.got 13904 13904 0 0.0
.init 24 24 0 0.0
.init_array 208 208 0 0.0
.rodata 504364 504540 176 0.0
.text 8199284 8200036 752 0.0
thermostat-no-ble arm64 (read only) 2388692 2389636 944 0.0
(read/write) 143585 143601 16 0.0
.bss 55361 55361 0 0.0
.data 1816 1816 0 0.0
.data.rel.ro 77208 77232 24 0.0
.dynamic 560 560 0 0.0
.got 5184 5184 0 0.0
.init 24 24 0 0.0
.init_array 440 440 0 0.0
.rodata 144124 144300 176 0.1
.text 2001728 2002480 752 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2455640 2456016 376 0.0
.bss 215044 215044 0 0.0
.data 5872 5872 0 0.0
.text 1418284 1418660 376 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1182083 1182455 372 0.0
bss 143633 143633 0 0.0
rodata 144196 144376 180 0.1
text 815304 815496 192 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1160735 1161091 356 0.0
bss 142860 142860 0 0.0
rodata 135768 135948 180 0.1
text 803172 803360 188 0.0
psoc6 all-clusters cy8ckit_062s2_43012 0 0 0 0.0
(read only) 841968 841968 0 0.0
(read/write) 1744332 1744732 400 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 188712 188712 0 0.0
.comment 204 204 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2664 2664 0 0.0
.debug_abbrev 1229274 1229290 16 0.0
.debug_aranges 111840 111840 0 0.0
.debug_frame 373436 373436 0 0.0
.debug_info 26822263 26823236 973 0.0
.debug_line 3670325 3670828 503 0.0
.debug_loc 3583707 3584515 808 0.0
.debug_ranges 340200 340272 72 0.0
.debug_str 3440007 3440051 44 0.0
.heap 841968 841968 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 288 288 0 0.0
.stab 156 156 0 0.0
.stabstr 335 335 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 569581 569581 0 0.0
.symtab 421104 421136 32 0.0
.text 1544568 1544968 400 0.0
.zero.table 8 8 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 0 0 0 0.0
(read only) 842704 842704 0 0.0
(read/write) 1686932 1687332 400 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 187976 187976 0 0.0
.comment 204 204 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2664 2664 0 0.0
.debug_abbrev 1221073 1221089 16 0.0
.debug_aranges 111312 111312 0 0.0
.debug_frame 376516 376516 0 0.0
.debug_info 26559045 26560019 974 0.0
.debug_line 3691041 3691544 503 0.0
.debug_loc 3571344 3572152 808 0.0
.debug_ranges 338816 338888 72 0.0
.debug_str 3429020 3429064 44 0.0
.heap 842704 842704 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 288 288 0 0.0
.stab 156 156 0 0.0
.stabstr 335 335 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 533670 533670 0 0.0
.symtab 407536 407568 32 0.0
.text 1487904 1488304 400 0.0
.zero.table 8 8 0 0.0
light cy8ckit_062s2_43012 0 0 0 0.0
(read only) 850896 850896 0 0.0
(read/write) 1605476 1605868 392 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 179992 179992 0 0.0
.comment 204 204 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2456 2456 0 0.0
.debug_abbrev 1055129 1055145 16 0.0
.debug_aranges 103520 103520 0 0.0
.debug_frame 346844 346844 0 0.0
.debug_info 22023240 22024214 974 0.0
.debug_line 3260959 3261462 503 0.0
.debug_loc 3269410 3270218 808 0.0
.debug_ranges 304144 304216 72 0.0
.debug_str 3234552 3234596 44 0.0
.heap 850896 850896 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 288 288 0 0.0
.stab 156 156 0 0.0
.stabstr 335 335 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 470047 470047 0 0.0
.symtab 375984 376016 32 0.0
.text 1414640 1415032 392 0.0
.zero.table 8 8 0 0.0
lock cy8ckit_062s2_43012 0 0 0 0.0
(read only) 845864 845864 0 0.0
(read/write) 1643340 1643732 392 0.0
.ARM.attributes 46 46 0 0.0
.ARM.exidx 8 8 0 0.0
.bss 185008 185008 0 0.0
.comment 204 204 0 0.0
.copy.table 24 24 0 0.0
.cy_m0p_image 6216 6216 0 0.0
.cy_sharedmem 8 8 0 0.0
.data 2472 2472 0 0.0
.debug_abbrev 1062548 1062564 16 0.0
.debug_aranges 104192 104192 0 0.0
.debug_frame 349668 349668 0 0.0
.debug_info 22402592 22403566 974 0.0
.debug_line 3269675 3270178 503 0.0
.debug_loc 3309282 3310090 808 0.0
.debug_ranges 307488 307560 72 0.0
.debug_str 3262007 3262051 44 0.0
.heap 845864 845864 0 0.0
.noinit 148 148 0 0.0
.ramVectors 736 736 0 0.0
.shstrtab 288 288 0 0.0
.stab 156 156 0 0.0
.stabstr 335 335 0 0.0
.stack_dummy 4096 4096 0 0.0
.strtab 476287 476287 0 0.0
.symtab 379216 379248 32 0.0
.text 1447472 1447864 392 0.0
.zero.table 8 8 0 0.0
qpg lighting-app qpg6105+debug (read/write) 1148140 1148516 376 0.0
.bss 110348 110348 0 0.0
.data 832 832 0 0.0
.text 595240 595616 376 0.1
lock-app qpg6105+debug (read/write) 1116060 1116428 368 0.0
.bss 106172 106172 0 0.0
.data 836 836 0 0.0
.text 563156 563524 368 0.1
telink light-switch-app tlsr9518adk80d (read/write) 813708 814084 376 0.0
bss 71372 71372 0 0.0
noinit 43488 43488 0 0.0
text 574610 574800 190 0.0
lighting-app tlsr9518adk80d (read/write) 835812 836188 376 0.0
bss 72228 72228 0 0.0
noinit 43488 43488 0 0.0
text 592828 593020 192 0.0
ota-requestor-app tlsr9518adk80d (read/write) 843772 844148 376 0.0
bss 73136 73136 0 0.0
noinit 43488 43488 0 0.0
text 599014 599204 190 0.0

@andy31415 andy31415 merged commit 4589a52 into project-chip:v1.0-branch Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants