Skip to content

Commit

Permalink
Terminate blocked receive packets on failure. Fixes #3168.
Browse files Browse the repository at this point in the history
  • Loading branch information
eholk committed Aug 10, 2012
1 parent 0101125 commit 4808d59
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libcore/pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,23 @@ fn try_recv<T: send, Tbuffer: send>(-p: recv_packet_buffered<T, Tbuffer>)
let p_ = p.unwrap();
let p = unsafe { &*p_ };

struct drop_state {
p: &packet_header;

drop {
if task::failing() {
io::println("failing!");
self.p.state = terminated;
let old_task = swap_task(self.p.blocked_task, ptr::null());
if !old_task.is_null() {
rustrt::rust_task_deref(old_task);
}
}
}
};

let _drop_state = drop_state { p: &p.header };

// optimistic path
match p.header.state {
full => {
Expand Down
19 changes: 19 additions & 0 deletions src/test/run-pass/issue-3168.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn main() {
let (c,p) = pipes::stream();
do task::try {
let (c2,p2) = pipes::stream();
do task::spawn {
p2.recv();
#error["brother fails"];
fail;
}
let (c3,p3) = pipes::stream();
c.send(c3);
c2.send(());
#error["child blocks"];
p3.recv();
};
#error["parent tries"];
assert !p.recv().try_send(());
#error("all done!");
}

0 comments on commit 4808d59

Please sign in to comment.