Bug 15284 - mdsearch leaking files in msg.sock and msg.lock
Summary: mdsearch leaking files in msg.sock and msg.lock
Status: NEW
Alias: None
Product: Samba 4.1 and newer
Classification: Unclassified
Component: Other (show other bugs)
Version: 4.15.13
Hardware: All All
: P5 normal (vote)
Target Milestone: ---
Assignee: Samba QA Contact
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-01-12 07:42 UTC by Jones Syue
Modified: 2023-01-16 09:23 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jones Syue 2023-01-12 07:42:05 UTC
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.
Comment 1 Jones Syue 2023-01-12 09:21:43 UTC
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]
Comment 3 Samba QA Contact 2023-01-12 11:41:03 UTC
This bug was referenced in samba master:

98d84192a03a4f1135eaf1590fb62b16d8bc49c8
Comment 4 Jones Syue 2023-01-16 09:23:23 UTC
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.