Skip to content

Commit 874455d

Browse files
authored
frame/io: Introduce Poisoned state for WriteState (#211)
Signed-off-by: Alexandru Vasile <[email protected]>
1 parent ba49769 commit 874455d

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

yamux/src/frame/io.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ enum WriteState {
5959
buffer: Vec<u8>,
6060
offset: usize,
6161
},
62+
Poisoned,
6263
}
6364

6465
impl fmt::Debug for WriteState {
@@ -76,6 +77,7 @@ impl fmt::Debug for WriteState {
7677
buffer.len()
7778
)
7879
}
80+
WriteState::Poisoned => f.write_str("(WriteState::Poisoned)"),
7981
}
8082
}
8183
}
@@ -103,10 +105,14 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sink<Frame<()>> for Io<T> {
103105
*offset += n;
104106

105107
if *offset > header.len() {
106-
return Poll::Ready(Err(io::Error::other(format!(
108+
let err = io::Error::other(format!(
107109
"Writer header returned invalid write count n={n}: {offset} > {} ",
108110
header.len(),
109-
))));
111+
));
112+
113+
this.write_state = WriteState::Poisoned;
114+
115+
return Poll::Ready(Err(err));
110116
}
111117

112118
if *offset == header.len() {
@@ -132,17 +138,26 @@ impl<T: AsyncRead + AsyncWrite + Unpin> Sink<Frame<()>> for Io<T> {
132138
*offset += n;
133139

134140
if *offset > buffer.len() {
135-
return Poll::Ready(Err(io::Error::other(format!(
141+
let err = io::Error::other(format!(
136142
"Writer body returned invalid write count n={n}: {offset} > {} ",
137143
buffer.len(),
138-
))));
144+
));
145+
146+
this.write_state = WriteState::Poisoned;
147+
148+
return Poll::Ready(Err(err));
139149
}
140150

141151
if *offset == buffer.len() {
142152
this.write_state = WriteState::Init;
143153
}
144154
}
145155
},
156+
WriteState::Poisoned => {
157+
return Poll::Ready(Err(io::Error::other(
158+
"Sink is in poisoned state due to previous write error",
159+
)))
160+
}
146161
}
147162
}
148163
}

0 commit comments

Comments
 (0)