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

Ensure the connection and the disconnect handler are accessed from th… #22732

Conversation

vivien-apple
Copy link
Contributor

…e same dispatch queue in MTRProtocolTests.m

Issue Being Resolved

While working on #22715 one of the Build Darwin tasks fails with:

2022-09-19T11:29:48.3083000Z 2022-09-19 11:29:48.304452+0000 xctest[5116:477757] XPC listener accepting connection
2022-09-19T11:29:48.3083430Z 2022-09-19 11:29:48.304936+0000 xctest[5116:477602] Subscribe attribute cache called
2022-09-19T11:29:48.3083900Z 2022-09-19 11:29:48.305292+0000 xctest[5116:477602] Attribute cache subscription succeeded for device 9876543210
2022-09-19T11:29:48.3084380Z 2022-09-19 11:29:48.305423+0000 xctest[5116:477602] Subscribe completion called with error: (null)
2022-09-19T11:29:48.3084820Z 2022-09-19 11:29:48.305529+0000 xctest[5116:477755] XPC connection disconnected
2022-09-19T11:29:48.3085240Z 2022-09-19 11:29:48.305837+0000 xctest[5116:477757] XPC listener accepting connection
2022-09-19T11:29:53.1864770Z /Users/runner/work/connectedhomeip/connectedhomeip/src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m:2290: error: -[MTRXPCProtocolTests testReadClusterStateCacheSuccess] : *** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2] (NSInvalidArgumentException)
2022-09-19T11:29:53.1957260Z Test Case '-[MTRXPCProtocolTests testReadClusterStateCacheSuccess]' failed (4.884 seconds).```

Also there has been a few other intermittent failures stating things like: 

src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m:177: error: -[MTRXPCProtocolTests testReadClusterStateCacheSuccess] : ((_xpcConnection) == nil) failed: "<NSXPCConnection: 0x7f883f1c1ac0> connection on anonymousListener or serviceListener from pid 19984"```

src/darwin/Framework/CHIPTests/MTRXPCProtocolTests.m:2299: error: -[MTRXPCProtocolTests testReadClusterStateCacheSuccess] : ((_xpcConnection) == nil) failed: "<NSXPCConnection: 0x7fbb09333920> connection on anonymousListener or serviceListener from pid 21964"

The first failure (the one with [__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2] (NSInvalidArgumentException)happens when the xpc disconnect handler is set to nil.
It happens because it was read and written from different dispatch queues.

Those can be reproduce by adding some code to MTRProtocolTests.m:

- (void)invokeTest
{
    for (int i=0; I<100000; i++) {
        [super invokeTest];
    }    
}

And then running those with the following command:
xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -only-testing:MatterTests/MTRXPCProtocolTests/testReadClusterStateCacheSuccess

With the following PR I can not reproduce it.

Change overview

  • This PR ensure that accessing/setting the connection and the disconnection handler happens onto the same dispatch queue to prevent races.

@github-actions
Copy link

github-actions bot commented Sep 19, 2022

PR #22732: Size comparison from 0cf7694 to 46b65f3

Increases (8 builds for bl602, bl702, cc13x2_26x2, esp32, nrfconnect, psoc6, qpg)
platform target config section 0cf7694 46b65f3 change % change
bl602 lighting-app bl602+rpc .text 1096276 1096278 2 0.0
bl702 lighting-app bl702 .debug_info 37894805 37894806 1 0.0
.text 956796 956798 2 0.0
cc13x2_26x2 lock-ftd LP_CC2652R7 (read only) 678103 678111 8 0.0
.text 600336 600344 8 0.0
esp32 all-clusters-app c3devkit (read/write) 1788038 1788046 8 0.0
.flash.rodata 257608 257616 8 0.0
nrfconnect all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1161455 1161471 16 0.0
text 803136 803140 4 0.0
psoc6 light cy8ckit_062s2_43012 .debug_info 22016667 22016668 1 0.0
lock cy8ckit_062s2_43012 .debug_info 22396004 22396005 1 0.0
qpg lighting-app qpg6105+debug (read/write) 1130780 1130788 8 0.0
.text 577876 577884 8 0.0
Decreases (2 builds for cc13x2_26x2, psoc6)
platform target config section 0cf7694 46b65f3 change % change
cc13x2_26x2 lock-ftd LP_CC2652R7 (read/write) 170600 170592 -8 -0.0
psoc6 all-clusters-minimal cy8ckit_062s2_43012 .debug_info 26552489 26552488 -1 -0.0
Full report (37 builds for bl602, bl702, cc13x2_26x2, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
platform target config section 0cf7694 46b65f3 change % change
bl602 lighting-app bl602 (read/write) 1383286 1383286 0 0.0
.bss 89537 89537 0 0.0
.data 9816 9816 0 0.0
.text 1064930 1064930 0 0.0
bl602+rpc (read/write) 1428482 1428482 0 0.0
.bss 96969 96969 0 0.0
.data 10200 10200 0 0.0
.text 1096276 1096278 2 0.0
bl702 lighting-app bl702 (read only) 3262 3262 0 0.0
(read/write) 1188147 1188147 0 0.0
.bleromro 6296 6296 0 0.0
.bleromrw 124 124 0 0.0
.boot2 688 688 0 0.0
.bss 67078 67078 0 0.0
.bss_psram 29696 29696 0 0.0
.comment 48 48 0 0.0
.data 4280 4280 0 0.0
.debug_abbrev 1506715 1506715 0 0.0
.debug_aranges 133088 133088 0 0.0
.debug_frame 486412 486412 0 0.0
.debug_info 37894805 37894806 1 0.0
.debug_line 5252100 5252100 0 0.0
.debug_loc 3362437 3362437 0 0.0
.debug_ranges 359712 359712 0 0.0
.debug_str 3455772 3455772 0 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 116488 116488 0 0.0
.rsvd 3188 3188 0 0.0
.shstrtab 293 293 0 0.0
.stack 2048 2048 0 0.0
.strtab 564895 564895 0 0.0
.symtab 171616 171616 0 0.0
.tcm_data 36 36 0 0.0
.tcmcode 3262 3262 0 0.0
.text 0 0 0 0.0
956796 956798 2 0.0
bl702+rpc (read only) 3262 3262 0 0.0
(read/write) 1284075 1284075 0 0.0
.bleromro 6296 6296 0 0.0
.bleromrw 124 124 0 0.0
.boot2 688 688 0 0.0
.bss 75126 75126 0 0.0
.bss_psram 29936 29936 0 0.0
.comment 48 48 0 0.0
.data 4800 4800 0 0.0
.debug_abbrev 1644294 1644294 0 0.0
.debug_aranges 140592 140592 0 0.0
.debug_frame 511788 511788 0 0.0
.debug_info 41801423 41801423 0 0.0
.debug_line 5626639 5626639 0 0.0
.debug_loc 3555144 3555144 0 0.0
.debug_ranges 382168 382168 0 0.0
.debug_str 3851739 3851739 0 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 129896 129896 0 0.0
.rsvd 3188 3188 0 0.0
.shstrtab 293 293 0 0.0
.stack 2048 2048 0 0.0
.strtab 624068 624068 0 0.0
.symtab 189424 189424 0 0.0
.tcm_data 36 36 0 0.0
.tcmcode 3262 3262 0 0.0
.text 0 0 0 0.0
1030496 1030496 0 0.0
cc13x2_26x2 all-clusters-app LP_CC2652R7 (read only) 676571 676571 0 0.0
(read/write) 174964 174964 0 0.0
.bss 81228 81228 0 0.0
.data 3380 3380 0 0.0
.rodata 89603 89603 0 0.0
.text 586656 586656 0 0.0
all-clusters-minimal-app LP_CC2652R7 (read only) 640819 640819 0 0.0
(read/write) 157996 157996 0 0.0
.bss 80500 80500 0 0.0
.data 3380 3380 0 0.0
.rodata 78739 78739 0 0.0
.text 561760 561760 0 0.0
lock-ftd LP_CC2652R7 (read only) 678103 678111 8 0.0
(read/write) 170600 170592 -8 -0.0
.bss 78484 78484 0 0.0
.data 3304 3304 0 0.0
.rodata 77287 77287 0 0.0
.text 600336 600344 8 0.0
lock-mtd LP_CC2652R7 (read only) 661923 661923 0 0.0
(read/write) 182468 182468 0 0.0
.bss 74172 74172 0 0.0
.data 3304 3304 0 0.0
.rodata 103123 103123 0 0.0
.text 558320 558320 0 0.0
pump-app LP_CC2652R7 (read only) 687267 687267 0 0.0
(read/write) 162140 162140 0 0.0
.bss 78420 78420 0 0.0
.data 3296 3296 0 0.0
.rodata 90507 90507 0 0.0
.text 596276 596276 0 0.0
pump-controller-app LP_CC2652R7 (read only) 671759 671759 0 0.0
(read/write) 177760 177760 0 0.0
.bss 78532 78532 0 0.0
.data 3292 3292 0 0.0
.rodata 86063 86063 0 0.0
.text 585216 585216 0 0.0
shell LP_CC2652R7 (read only) 667598 667598 0 0.0
(read/write) 186248 186248 0 0.0
.bss 83540 83540 0 0.0
.data 3376 3376 0 0.0
.rodata 86318 86318 0 0.0
.text 580964 580964 0 0.0
cyw30739 light cyw930739m2evb_01 (read/write) 587322 587322 0 0.0
.app_xip_area 463980 463980 0 0.0
.bss 65776 65776 0 0.0
.data 744 744 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
lock cyw930739m2evb_01 (read/write) 594370 594370 0 0.0
.app_xip_area 465700 465700 0 0.0
.bss 71096 71096 0 0.0
.data 752 752 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
ota-requestor-no-progress-logging cyw930739m2evb_01 (read/write) 543314 543314 0 0.0
.app_xip_area 424996 424996 0 0.0
.bss 60784 60784 0 0.0
.data 716 716 0 0.0
.rodata 0 0 0 0.0
.text 112 112 0 0.0
efr32 lighting-app BRD4161A (read/write) 1110488 1110488 0 0.0
.bss 136532 136532 0 0.0
.data 2072 2072 0 0.0
.text 971864 971864 0 0.0
BRD4161A+rpc (read/write) 973628 973628 0 0.0
.bss 151044 151044 0 0.0
.data 2252 2252 0 0.0
.text 820312 820312 0 0.0
BRD4161A+rs911x (read/write) 1003736 1003736 0 0.0
.bss 169368 169368 0 0.0
.data 2064 2064 0 0.0
.text 832284 832284 0 0.0
lock-app BRD4161A+wf200 (read/write) 1151292 1151292 0 0.0
.bss 152248 152248 0 0.0
.data 2072 2072 0 0.0
.text 996952 996952 0 0.0
window-app BRD4161A (read/write) 1102536 1102536 0 0.0
.bss 137980 137980 0 0.0
.data 2096 2096 0 0.0
.text 962440 962440 0 0.0
esp32 all-clusters-app c3devkit (read only) 1222910 1222910 0 0.0
(read/write) 1788038 1788046 8 0.0
.dram0.bss 76944 76944 0 0.0
.dram0.data 13840 13840 0 0.0
.flash.rodata 257608 257616 8 0.0
.flash.text 1222910 1222910 0 0.0
.iram0.text 65204 65204 0 0.0
m5stack (read only) 1232975 1232975 0 0.0
(read/write) 563940 563940 0 0.0
.dram0.bss 82304 82304 0 0.0
.dram0.data 34296 34296 0 0.0
.flash.rodata 314672 314672 0 0.0
.flash.text 1227591 1227591 0 0.0
.iram0.text 123939 123939 0 0.0
k32w light k32w0+release (read/write) 649868 649868 0 0.0
.bss 70712 70712 0 0.0
.data 2068 2068 0 0.0
.text 574360 574360 0 0.0
lock k32w0+release (read/write) 706824 706824 0 0.0
.bss 71160 71160 0 0.0
.data 2076 2076 0 0.0
.text 630860 630860 0 0.0
linux chip-tool-ipv6only arm64 (read only) 10353140 10353140 0 0.0
(read/write) 706241 706241 0 0.0
.bss 33937 33937 0 0.0
.data 2864 2864 0 0.0
.data.rel.ro 650560 650560 0 0.0
.dynamic 560 560 0 0.0
.got 13904 13904 0 0.0
.init 24 24 0 0.0
.init_array 200 200 0 0.0
.rodata 503844 503844 0 0.0
.text 8195348 8195348 0 0.0
thermostat-no-ble arm64 (read only) 2386892 2386892 0 0.0
(read/write) 143617 143617 0 0.0
.bss 55345 55345 0 0.0
.data 1912 1912 0 0.0
.data.rel.ro 77208 77208 0 0.0
.dynamic 560 560 0 0.0
.got 5184 5184 0 0.0
.init 24 24 0 0.0
.init_array 432 432 0 0.0
.rodata 143636 143636 0 0.0
.text 2000992 2000992 0 0.0
mbed lock-app CY8CPROTO_062_4343W+release (read only) 6224 6224 0 0.0
(read/write) 2455640 2455640 0 0.0
.bss 215044 215044 0 0.0
.data 5872 5872 0 0.0
.text 1418284 1418284 0 0.0
nrfconnect all-clusters-app nrf52840dk_nrf52840 (read/write) 1182819 1182819 0 0.0
bss 144433 144433 0 0.0
rodata 144196 144196 0 0.0
text 815272 815272 0 0.0
all-clusters-minimal-app nrf52840dk_nrf52840 (read/write) 1161455 1161471 16 0.0
bss 143660 143660 0 0.0
rodata 135768 135768 0 0.0
text 803136 803140 4 0.0
psoc6 all-clusters cy8ckit_062s2_43012 (read only) 841968 841968 0 0.0
(read/write) 1743884 1743884 0 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 1229301 1229301 0 0.0
.debug_aranges 111800 111800 0 0.0
.debug_frame 373268 373268 0 0.0
.debug_info 26815706 26815706 0 0.0
.debug_line 3667850 3667850 0 0.0
.debug_loc 3580124 3580124 0 0.0
.debug_ranges 339904 339904 0 0.0
.debug_str 3439416 3439416 0 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 569356 569356 0 0.0
.symtab 421168 421168 0 0.0
.text 1544120 1544120 0 0.0
.zero.table 8 8 0 0.0
text 0 0 0 0.0
all-clusters-minimal cy8ckit_062s2_43012 (read only) 842704 842704 0 0.0
(read/write) 1686492 1686492 0 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 1221100 1221100 0 0.0
.debug_aranges 111272 111272 0 0.0
.debug_frame 376348 376348 0 0.0
.debug_info 26552489 26552488 -1 -0.0
.debug_line 3688566 3688566 0 0.0
.debug_loc 3567761 3567761 0 0.0
.debug_ranges 338520 338520 0 0.0
.debug_str 3428429 3428429 0 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 533445 533445 0 0.0
.symtab 407600 407600 0 0.0
.text 1487464 1487464 0 0.0
.zero.table 0 0 0 0.0
8 8 0 0.0
light cy8ckit_062s2_43012 (read only) 850896 850896 0 0.0
(read/write) 1605044 1605044 0 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 1055156 1055156 0 0.0
.debug_aranges 103480 103480 0 0.0
.debug_frame 346676 346676 0 0.0
.debug_info 22016667 22016668 1 0.0
.debug_line 3258486 3258486 0 0.0
.debug_loc 3265868 3265868 0 0.0
.debug_ranges 303848 303848 0 0.0
.debug_str 3233961 3233961 0 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 469822 469822 0 0.0
.symtab 376048 376048 0 0.0
.text 1414208 1414208 0 0.0
.zero.table 0 0 0 0.0
8 8 0 0.0
lock cy8ckit_062s2_43012 (read only) 845864 845864 0 0.0
(read/write) 1642668 1642668 0 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 1062575 1062575 0 0.0
.debug_aranges 104152 104152 0 0.0
.debug_frame 349500 349500 0 0.0
.debug_info 22396004 22396005 1 0.0
.debug_line 3267178 3267178 0 0.0
.debug_loc 3305696 3305696 0 0.0
.debug_ranges 307192 307192 0 0.0
.debug_str 3261416 3261416 0 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 476025 476025 0 0.0
.symtab 379232 379232 0 0.0
.text 1446800 1446800 0 0.0
.zero.table 0 0 0 0.0
8 8 0 0.0
qpg lighting-app qpg6105+debug (read/write) 1130780 1130788 8 0.0
.bss 106312 106312 0 0.0
.data 1028 1028 0 0.0
.text 577876 577884 8 0.0
lock-app qpg6105+debug (read/write) 1101768 1101768 0 0.0
.bss 102544 102544 0 0.0
.data 1032 1032 0 0.0
.text 548868 548868 0 0.0
telink light-switch-app tlsr9518adk80d (read/write) 814452 814452 0 0.0
bss 72172 72172 0 0.0
noinit 43488 43488 0 0.0
text 574552 574552 0 0.0
lighting-app tlsr9518adk80d (read/write) 836408 836408 0 0.0
bss 73028 73028 0 0.0
noinit 43488 43488 0 0.0
text 592714 592714 0 0.0
ota-requestor-app tlsr9518adk80d (read/write) 844508 844508 0 0.0
bss 73936 73936 0 0.0
noinit 43488 43488 0 0.0
text 598952 598952 0 0.0

@vivien-apple vivien-apple merged commit 2466360 into project-chip:master Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants