mdsearch utility would exit earlier with failure in several cases like: a. samba server is not running yet, [~] # mdsearch -Uuser%password1 ${server} Public '*=="Samba"' main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED b. spotlight backend service is not ready yet, [~] # mdsearch -Uuser%password1 ${server} Public '*=="Samba"' Failed to connect mdssvc c. mdsearch utility paramters is not as expecred, [~] # mdsearch -Uuser%password1 ${server} share_not_exist '*=="Samba"' mdscli_search failed And in the mean while once mdsearch utility exit earlier with failure, the lock files are left behind in the directory 'msg.sock' and 'msg.lock'. If a script to run mdsearch utility in a loop, this might result in used space slowly growing-up on underlying filesystem. Supposed to add a new label 'fail_free_messaging', make it go through the cmdline_messaging_context_free() which deletes the lock files in the directory msg.sock and msg.lock before mdsearch utility is exiting with failure. patch will follow.
1) Before patch: mdsearch utility would exit earlier if server is not running yet, the lock entries '12827' are left behind in the 'msg.sock' and 'msg.lock'. [~] # strace mdsearch -Uuser%password1 ${server} Public '*=="Samba"' 2>&1 | grep -E "msg..ock/|Cannot connect" open("/var/lock/.samba/lock/msg.lock/12827", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 5 unlink("/usr/local/samba/private/msg.sock/12827") = -1 ENOENT (No such file or directory) bind(6, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/12827"}, 110) = 0 write(2, "main: Cannot connect to server: "..., 61main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED [~] # [~] # ls /var/lock/.samba/lock/msg.lock/ /usr/local/samba/private/msg.sock/ /usr/local/samba/private/msg.sock/: 12827= /var/lock/.samba/lock/msg.lock/: 12827 [~] # 2) After patch: strace shows that the lock entries are created and then deleted before mdsearch utility is exiting. [~] # strace mdsearch -Uuser%password1 ${server} Public '*=="Samba"' 2>&1 | grep -E "msg..ock/|Cannot connect" open("/var/lock/.samba/lock/msg.lock/14401", O_RDWR|O_CREAT|O_NONBLOCK, 0644) = 5 unlink("/usr/local/samba/private/msg.sock/14401") = -1 ENOENT (No such file or directory) bind(6, {sa_family=AF_UNIX, sun_path="/usr/local/samba/private/msg.sock/14401"}, 110) = 0 write(2, "main: Cannot connect to server: "..., 61main: Cannot connect to server: NT_STATUS_CONNECTION_REFUSED unlink("/usr/local/samba/private/msg.sock/14401") = 0 unlink("/var/lock/.samba/lock/msg.lock/14401") = 0 [~] # strace with '-k' shows that the destructor is triggered. unlink("/usr/local/samba/private/msg.sock/15817") = 0 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x12a) [0x370a] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x51dbc] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(main+0x4b6) [0x4286] > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(_start+0x29) [0x4509] unlink("/var/lock/.samba/lock/msg.lock/15817") = 0 > /lib/libc-2.21.so(unlink+0x7) [0xdccb7] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_context_destructor+0x155) [0x3735] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(messaging_dgm_destroy+0x1c) [0x4f7c] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libmessages-dgm-samba4.so(msg_dgm_ref_destructor+0xc5) [0x5e85] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0xcc9) [0x37a9] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/private/libtalloc.so.2.3.3(_tc_free_internal+0x160) [0x2c40] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/lib/libsmbconf.so.0.0.1(global_messaging_context_free+0x1c) [0x51dbc] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(main+0x4b6) [0x4286] > /lib/libc-2.21.so(__libc_start_main+0xf0) [0x20810] > /share/CACHEDEV1_DATA/Public/20230112_s41513_debug_fixmdsearch/samba/bin/mdsearch(_start+0x29) [0x4509]
patch against master: https://gitlab.com/samba-team/devel/samba/-/commit/64e84358b97 CI pipeline is passed: https://gitlab.com/samba-team/devel/samba/-/pipelines/745131057 merge request: https://gitlab.com/samba-team/samba/-/merge_requests/2882
This bug was referenced in samba master: 98d84192a03a4f1135eaf1590fb62b16d8bc49c8
Thank you for kindly review! Just for reference: my test version is 4.15.13, so 4.16 & 4.17 might have this issue too.
Created attachment 17752 [details] fix for v4-17-test, cherry-picked from master fix for v4-17-test, cherry-picked from master
Created attachment 17753 [details] fix for v4-16-test, cherry-picked from master
Friendly ping :) could we pick this fix into 4.17 and 4.16, thank you.
Resolved Fixed since this is in master :)