Skip to content

Notice callback drop timing in add_route#431

Merged
jdm merged 2 commits intoservo:mainfrom
Legend-Master:add-route-drop-docs
Jan 2, 2026
Merged

Notice callback drop timing in add_route#431
jdm merged 2 commits intoservo:mainfrom
Legend-Master:add-route-drop-docs

Conversation

@Legend-Master
Copy link
Copy Markdown
Contributor

I have tried to look up if I could listen to channel disconnects on a IpcReceiver when I'm using the ROUTER and only found out that the callback is dropped on receiver's channel disconnects so I could move a drop guard in to the handler after looking into the actual implementation, so I thought it might be good to document this

Copy link
Copy Markdown
Contributor

@glyn glyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for documenting this behaviour. Could you also add a test?

Comment thread src/router.rs Outdated
Comment thread src/router.rs Outdated
@Legend-Master
Copy link
Copy Markdown
Contributor Author

Could you also add a test?

They already exist:

ipc-channel/src/test.rs

Lines 419 to 473 in e5f8add

#[test]
fn router_drops_callbacks_on_sender_shutdown() {
struct Dropper {
sender: Sender<i32>,
}
impl Drop for Dropper {
fn drop(&mut self) {
self.sender.send(42).unwrap();
}
}
let (tx0, rx0) = ipc::channel::<()>().unwrap();
let (drop_tx, drop_rx) = crossbeam_channel::unbounded();
let dropper = Dropper { sender: drop_tx };
let router = RouterProxy::new();
router.add_typed_route(
rx0,
Box::new(move |_| {
let _ = &dropper;
}),
);
drop(tx0);
assert_eq!(drop_rx.recv(), Ok(42));
}
#[test]
fn router_drops_callbacks_on_cloned_sender_shutdown() {
struct Dropper {
sender: Sender<i32>,
}
impl Drop for Dropper {
fn drop(&mut self) {
self.sender.send(42).unwrap()
}
}
let (tx0, rx0) = ipc::channel::<()>().unwrap();
let (drop_tx, drop_rx) = crossbeam_channel::unbounded();
let dropper = Dropper { sender: drop_tx };
let router = RouterProxy::new();
router.add_typed_route(
rx0,
Box::new(move |_| {
let _ = &dropper;
}),
);
let txs = vec![tx0.clone(), tx0.clone(), tx0.clone()];
drop(txs);
drop(tx0);
assert_eq!(drop_rx.recv(), Ok(42));
}

@jdm jdm enabled auto-merge January 2, 2026 14:29
@jdm jdm added this pull request to the merge queue Jan 2, 2026
Merged via the queue into servo:main with commit 6d922c3 Jan 2, 2026
25 checks passed
@Legend-Master Legend-Master deleted the add-route-drop-docs branch January 2, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants