Skip to content

Commit 74e12fc

Browse files
committed
Ignore upcall_flush for channels that are disassociated from ports. This makes task-comm-10 break a little less hard, but it still leaks because messages pending in the channel are never freed.
1 parent c56ecc1 commit 74e12fc

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

src/rt/circular_buffer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,8 @@ bool
142142
circular_buffer::is_empty() {
143143
return _unread == 0;
144144
}
145+
146+
size_t
147+
circular_buffer::size() {
148+
return _unread;
149+
}

src/rt/circular_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ circular_buffer : public dom_owned<circular_buffer> {
2121
void dequeue(void *dst);
2222
uint8_t *peek();
2323
bool is_empty();
24+
size_t size();
2425

2526
private:
2627
// Size of the buffer in bytes, should always be a power of two so that

src/rt/rust_port.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ void rust_port::log_state() {
5454
for (uint32_t i = 0; i < chans.length(); i++) {
5555
rust_chan *chan = chans[i];
5656
task->log(rust_log::COMM,
57-
"\tchan: 0x%" PRIxPTR ", data pending: %s, remote: %s",
57+
"\tchan: 0x%" PRIxPTR ", size: %d, remote: %s",
5858
chan,
59-
!chan->buffer.is_empty() ? "yes" : "no",
59+
chan->buffer.size(),
6060
chan == remote_channel ? "yes" : "no");
6161
}
6262
}

src/rt/rust_upcall.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ upcall_flush_chan(rust_task *task, rust_chan *chan) {
116116
return;
117117
}
118118

119+
// We cannot flush if the target port was dropped.
120+
if (chan->is_associated() == false) {
121+
return;
122+
}
123+
124+
A(dom, chan->is_associated(),
125+
"Channel should be associated to a port.");
126+
119127
A(dom, chan->port->is_proxy() == false,
120128
"Channels to remote ports should be flushed automatically.");
121129

src/test/run-pass/task-comm-10.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ io fn start(chan[chan[str]] c) {
22
let port[str] p = port();
33
c <| chan(p);
44
auto a <- p;
5-
auto b <- p;
6-
// Never read the second string.
5+
// auto b <- p; // Never read the second string.
76
}
87

98
io fn main() {

0 commit comments

Comments
 (0)