Skip to content

Commit ae74ac3

Browse files
committed
[eclipse-iceoryx#139] Fix uds does not corrupt notifier when listener goes out of scope
1 parent 54b3eab commit ae74ac3

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

iceoryx2-bb/posix/src/unix_datagram_socket.rs

+2
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ enum_gen! {
189189
entry:
190190
MessageTooLarge,
191191
ConnectionReset,
192+
ConnectionRefused,
192193
Interrupt,
193194
IOerror,
194195
InsufficientPermissions,
@@ -694,6 +695,7 @@ impl UnixDatagramSender {
694695
handle_errno!(UnixDatagramSendError, from self,
695696
success Errno::EAGAIN => false,
696697
Errno::ECONNRESET => (ConnectionReset, "{} since the connection was reset by peer.", msg),
698+
Errno::ECONNREFUSED => (ConnectionRefused, "{} since the connection was refused by peer.", msg),
697699
Errno::EINTR => (Interrupt, "{} since an interrupt signal was received.", msg),
698700
Errno::EMSGSIZE => (MessageTooLarge, "{} since the message size of {} bytes is too large to be send in one package.", msg, data.len()),
699701
Errno::EIO => (IOerror, "{} since an I/O error occurred while writing to the file system.", msg),

iceoryx2-cal/src/event/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub use iceoryx2_bb_system_types::path::Path;
2828
pub enum NotifierNotifyError {
2929
FailedToDeliverSignal,
3030
TriggerIdOutOfBounds,
31+
Disconnected,
3132
InternalFailure,
3233
}
3334

iceoryx2-cal/src/event/unix_datagram_socket.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ impl crate::event::Notifier for Notifier {
139139
Ok(true) => Ok(()),
140140
Ok(false) | Err(UnixDatagramSendError::MessagePartiallySend(_)) => {
141141
fail!(from self, with NotifierNotifyError::FailedToDeliverSignal,
142-
"{} since the signal could not be delivered", msg);
142+
"{} since the signal could not be delivered.", msg);
143+
}
144+
Err(
145+
UnixDatagramSendError::ConnectionReset | UnixDatagramSendError::ConnectionRefused,
146+
) => {
147+
fail!(from self, with NotifierNotifyError::Disconnected,
148+
"{} since the notifier is no longer connected to the listener.", msg);
143149
}
144150
Err(v) => {
145151
fail!(from self, with NotifierNotifyError::InternalFailure,

iceoryx2-cal/tests/event_tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,20 @@ mod event {
612612
});
613613
}
614614

615+
#[test]
616+
fn out_of_scope_listener_shall_not_corrupt_notifier<Sut: Event>() {
617+
let name = generate_name();
618+
619+
let sut_listener = Sut::ListenerBuilder::new(&name).create().unwrap();
620+
let sut_notifier = Sut::NotifierBuilder::new(&name).open().unwrap();
621+
622+
drop(sut_listener);
623+
624+
let result = sut_notifier.notify(TriggerId::new(0));
625+
assert_that!(result, is_err);
626+
assert_that!(result.err().unwrap(), eq NotifierNotifyError::Disconnected);
627+
}
628+
615629
#[instantiate_tests(<iceoryx2_cal::event::unix_datagram_socket::EventImpl>)]
616630
mod unix_datagram {}
617631

iceoryx2/tests/service_event_tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ mod service_event {
431431
}
432432

433433
#[test]
434-
// TODO iox2-139, enable when bitset is integrated into events
435434
fn concurrent_reconnecting_notifier_can_trigger_waiting_listener<Sut: Service>() {
436435
let _watch_dog = Watchdog::new();
437436

0 commit comments

Comments
 (0)