chiark / gitweb /
apitest: handle broken pipe on sse copier
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 12:23:14 +0000 (12:23 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 13 Mar 2021 12:24:09 +0000 (12:24 +0000)
quel faff!

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
apitest/at-otter.rs

index ba07b3693675637a16221fcebfb1af1071dadb3e..9f07c7cb10b74ba96120f197d78a14b9ca9fc757 100644 (file)
@@ -148,7 +148,19 @@ impl Ctx {
     let (mut wpipe, rpipe) = UnixStream::pair()?;
     thread::spawn(move ||{
       eprintln!("copy_to'ing");
-      sse.copy_to(&mut wpipe).unwrap();
+      match sse.copy_to(&mut wpipe) {
+        Err(re) => match (||{
+          // reqwest::Error won't give us the underlying io::Error :-/
+          wpipe.write_all(b"\n")?;
+          wpipe.flush()?;
+          Ok::<_,io::Error>(())
+        })() {
+          Err(pe) if pe.kind() == ErrorKind::BrokenPipe => { Ok(()) }
+          Err(pe) => Err(AE::from(pe)),
+          Ok(_) => Err(AE::from(re)),
+        }
+        Ok(_n) => Ok(()),
+      }.unwrap();
       eprintln!("copy_to'd!"); 
     });