mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-19 12:14:11 +00:00
agent: don't do anything in Pipestream::shutdown
The only right way to shutdown pipe is drop it Otherwise PipeStream will conflict with its twins Because they both have the same fd, and both registered. Fixes: #1614 Signed-off-by: Tim Zhang <tim@hyper.sh>
This commit is contained in:
parent
5524bc806b
commit
4a2d437043
@ -77,10 +77,6 @@ impl PipeStream {
|
|||||||
Ok(Self(AsyncFd::new(StreamFd(fd))?))
|
Ok(Self(AsyncFd::new(StreamFd(fd))?))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shutdown(&mut self) -> io::Result<()> {
|
|
||||||
self.0.get_mut().close()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn from_fd(fd: RawFd) -> Self {
|
pub fn from_fd(fd: RawFd) -> Self {
|
||||||
unsafe { Self::from_raw_fd(fd) }
|
unsafe { Self::from_raw_fd(fd) }
|
||||||
}
|
}
|
||||||
@ -164,7 +160,10 @@ impl AsyncWrite for PipeStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
fn poll_shutdown(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
||||||
self.get_mut().shutdown()?;
|
// Do nothing in shutdown is very important
|
||||||
|
// The only right way to shutdown pipe is drop it
|
||||||
|
// Otherwise PipeStream will conflict with its twins
|
||||||
|
// Because they both have same fd, and both registered.
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,28 +117,20 @@ pub async fn write_async(pipe_w: &mut PipeStream, msg_type: i32, data_str: &str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
match msg_type {
|
match msg_type {
|
||||||
SYNC_FAILED => match write_count(pipe_w, data_str.as_bytes(), data_str.len()).await {
|
SYNC_FAILED => {
|
||||||
Ok(_) => pipe_w.shutdown()?,
|
if let Err(e) = write_count(pipe_w, data_str.as_bytes(), data_str.len()).await {
|
||||||
Err(e) => {
|
|
||||||
pipe_w.shutdown()?;
|
|
||||||
return Err(anyhow!(e).context("error in send message to process"));
|
return Err(anyhow!(e).context("error in send message to process"));
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
SYNC_DATA => {
|
SYNC_DATA => {
|
||||||
let length: i32 = data_str.len() as i32;
|
let length: i32 = data_str.len() as i32;
|
||||||
write_count(pipe_w, &length.to_be_bytes(), MSG_SIZE)
|
write_count(pipe_w, &length.to_be_bytes(), MSG_SIZE)
|
||||||
.await
|
.await
|
||||||
.or_else(|e| {
|
.map_err(|e| anyhow!(e).context("error in send message to process"))?;
|
||||||
pipe_w.shutdown()?;
|
|
||||||
Err(anyhow!(e).context("error in send message to process"))
|
|
||||||
})?;
|
|
||||||
|
|
||||||
write_count(pipe_w, data_str.as_bytes(), data_str.len())
|
write_count(pipe_w, data_str.as_bytes(), data_str.len())
|
||||||
.await
|
.await
|
||||||
.or_else(|e| {
|
.map_err(|e| anyhow!(e).context("error in send message to process"))?;
|
||||||
pipe_w.shutdown()?;
|
|
||||||
Err(anyhow!(e).context("error in send message to process"))
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => (),
|
_ => (),
|
||||||
|
Loading…
Reference in New Issue
Block a user