Skip to content

Commit 4808d59

Browse files
committed
Terminate blocked receive packets on failure. Fixes #3168.
1 parent 0101125 commit 4808d59

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/libcore/pipes.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,23 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>)
396396
let p_ = p.unwrap();
397397
let p = unsafe { &*p_ };
398398

399+
struct drop_state {
400+
p: &packet_header;
401+
402+
drop {
403+
if task::failing() {
404+
io::println("failing!");
405+
self.p.state = terminated;
406+
let old_task = swap_task(self.p.blocked_task, ptr::null());
407+
if !old_task.is_null() {
408+
rustrt::rust_task_deref(old_task);
409+
}
410+
}
411+
}
412+
};
413+
414+
let _drop_state = drop_state { p: &p.header };
415+
399416
// optimistic path
400417
match p.header.state {
401418
full => {

src/test/run-pass/issue-3168.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
fn main() {
2+
let (c,p) = pipes::stream();
3+
do task::try {
4+
let (c2,p2) = pipes::stream();
5+
do task::spawn {
6+
p2.recv();
7+
#error["brother fails"];
8+
fail;
9+
}
10+
let (c3,p3) = pipes::stream();
11+
c.send(c3);
12+
c2.send(());
13+
#error["child blocks"];
14+
p3.recv();
15+
};
16+
#error["parent tries"];
17+
assert !p.recv().try_send(());
18+
#error("all done!");
19+
}

0 commit comments

Comments
 (0)