eclipse-iceoryx / iceoryx

Eclipse iceoryx™ - true zero-copy inter-process-communication
https://iceoryx.io
Apache License 2.0
1.62k stars 383 forks source link

mq_timedsend/mq_timedreceive can not work with time changes #472

Closed muzili closed 3 years ago

muzili commented 3 years ago

Required information

The mq_timedsend/mq_timedreceive use CLOCK_REALTIME, there's unpredicated behaviour when the system time changes. The message queue should use CLOCK_MONOTONIC to fix this.

Operating system: Customized embedded linux

Compiler version: arm-himix200-linux-gcc (HC&C V1R3C00SPC200B005_20190606) 6.3.0

Observed result or behaviour: core/third_party/iceoryx-rs/iceoryx/iceoryx_utils/source/posix_wrapper/message_queue.cpp:305 { iox::cxx::expected<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, iox::posix::IpcChannelError> iox::posix::MessageQueue::timedReceive(const iox::units::Duration&) const } ::: [ 22 ] Invalid argument

Expected result or behaviour: Works well with time changes.

Conditions where it occurred / Performed steps: Describe how one can reproduce the bug.

dkroenke commented 3 years ago

Hello @muzili, welcome to iceoryx and thanks for reporting. That's a valid point and i guess it happens in timedSend and timedReceive where units::Duration is used as timeout parameter. The timespec is there created based on units::TimeSpecReference::Epoch which is CLOCK_REALTIME. Changing that to units::TimeSpecReference::Monotonic could resolve the issue.

See MessageQueue::timedSend(const std::string& msg, const units::Duration& timeout) and MessageQueue::timedReceive(const units::Duration& timeout) in message_queue.cpp in iceoryx_utils.

If you want you can contribute and create a PR with a solution proposal for review or we take it up, just let us know here.

elBoberido commented 3 years ago

@muzili correct me if I'm wrong, but mq_timedsend requires an absolute timeout since 1970-01-01 00:00:00 +0000 (UTC). Doesn't this rule out CLOCK_MONOTONIC?

https://man7.org/linux/man-pages/man3/mq_send.3.html

muzili commented 3 years ago

@dkroenke @elBoberido This is the limitation for posix message queue, there's a detail explanation from https://stackoverflow.com/questions/33873374/pthreads-mq-timedreceive-pthread-cond-timedwait-and-clock-realtime

For QNX system, there's an alternative function mq_timedreceive_monotonic(). For Posix(Linux) system, it is better to change to unix domain socket.

dkroenke commented 3 years ago

@muzili We have already planned to use UDS on in iceoryx: https://github.com/eclipse-iceoryx/iceoryx/issues/381. Hopefully in the next weeks it will come in.

elBoberido commented 3 years ago

@muzili for QNX we also plan to use message passing, so in the end the message queue won't be used anymore.

dkroenke commented 3 years ago

@muzili We have merged the UDS protocol in iceoryx and do not use the MessageQueue anymore. I tried to reproduce the issue locally on Ubuntu 20.04 and it does not come up. Can you confirm this?

budrus commented 3 years ago

Closing this as we use UDS now