Could you possibly make a minimal, reproducible code example for this? Or share your original crate, if it's public?
There are differences in your two pieces of code, but if that's all your function is doing, then it shouldn't make any difference in practice. The biggest/only difference I know of is when the lock is unwrapped: if you had any statements after starting the discovering, in your former example, the lock would stay locked during those statements, and in your latter example, it'd be immediately unlocked after calling start_discovery.
The other possibility is that some code is exhibiting Undefined Behavior, either in your crate or in one of your dependencies, and that is causing intermittent miscompilation. Weird, completely unrelated code making things work or not work is a hallmark of unsound code and undefined behavior.
Thanks for your response.
I have created a repo to host a mwe (Maybe not minimal enough):
Yep.
Something that might be important: I haven't written the start_discovery method. It is automatically generated using a tool provided by the dbus-rs crate author. Also, I have slightly modified it (at Deref target level) to fit my need.