Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,12 +537,14 @@ impl Multi {
pub fn action(&self, socket: Socket, events: &Events) -> Result<u32, MultiError> {
let mut remaining = 0;
unsafe {
cvt(curl_sys::curl_multi_socket_action(
let ret = cvt(curl_sys::curl_multi_socket_action(
self.inner.raw.handle,
socket,
events.bits,
&mut remaining,
))?;
));
panic::propagate();
ret?;
Ok(remaining as u32)
}
}
Expand All @@ -565,12 +567,14 @@ impl Multi {
pub fn timeout(&self) -> Result<u32, MultiError> {
let mut remaining = 0;
unsafe {
cvt(curl_sys::curl_multi_socket_action(
let ret = cvt(curl_sys::curl_multi_socket_action(
self.inner.raw.handle,
curl_sys::CURL_SOCKET_BAD,
0,
&mut remaining,
))?;
));
panic::propagate();
ret?;
Ok(remaining as u32)
}
}
Expand Down Expand Up @@ -750,10 +754,12 @@ impl Multi {
pub fn perform(&self) -> Result<u32, MultiError> {
unsafe {
let mut ret = 0;
cvt(curl_sys::curl_multi_perform(
let res = cvt(curl_sys::curl_multi_perform(
self.inner.raw.handle,
&mut ret,
))?;
));
panic::propagate();
res?;
Ok(ret as u32)
}
}
Expand Down
44 changes: 44 additions & 0 deletions tests/multi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,47 @@ fn drop_easy_handle_before_multi() -> Result<(), Box<dyn Error>> {

Ok(())
}

#[test]
fn panic_in_callback_is_propagated() {
let s = Server::new();
s.receive(
"\
GET / HTTP/1.1\r\n\
Host: 127.0.0.1:$PORT\r\n\
Accept: */*\r\n\
\r\n",
);
s.send("HTTP/1.1 200 OK\r\n\r\n");

let m = Multi::new();
let mut e = Easy::new();
t!(e.url(&s.url("/")));
t!(e.header_function(|_| panic!("header callback panicked")));
let _e = t!(m.add(e));

let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
while t!(m.perform()) > 0 {
t!(m.wait(&mut [], Duration::from_secs(1)));
}
}));
let err = res.expect_err("panic in callback should reach the caller of perform");
assert_eq!(
err.downcast_ref::<&str>(),
Some(&"header callback panicked")
);

// The panic must not be left behind for an unrelated transfer.
let s2 = Server::new();
s2.receive(
"\
GET / HTTP/1.1\r\n\
Host: 127.0.0.1:$PORT\r\n\
Accept: */*\r\n\
\r\n",
);
s2.send("HTTP/1.1 200 OK\r\n\r\n");
let mut e2 = Easy::new();
t!(e2.url(&s2.url("/")));
t!(e2.perform());
}
Loading