@@ -2259,3 +2259,69 @@ func TestAttach_Isolated(t *testing.T) {
2259
2259
})
2260
2260
}
2261
2261
}
2262
+
2263
+ // errorBuffer simulates a broken pipe (EPIPE) case.
2264
+ type errorBuffer struct {
2265
+ }
2266
+
2267
+ func (errorBuffer ) Write (b []byte ) (int , error ) {
2268
+ return 0 , errors .Errorf ("failed to write %d bytes" , len (b ))
2269
+ }
2270
+
2271
+ func TestBrokenPipe_Isolated (t * testing.T ) {
2272
+ prepareIntegTest (t )
2273
+
2274
+ client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
2275
+ require .NoError (t , err , "unable to create client to containerd service at %s, is containerd running?" , containerdSockPath )
2276
+ defer client .Close ()
2277
+
2278
+ ctx := namespaces .WithNamespace (context .Background (), "default" )
2279
+
2280
+ image , err := alpineImage (ctx , client , defaultSnapshotterName )
2281
+ require .NoError (t , err , "failed to get alpine image" )
2282
+
2283
+ name := testNameToVMID (t .Name ())
2284
+
2285
+ c , err := client .NewContainer (ctx ,
2286
+ "container-" + name ,
2287
+ containerd .WithSnapshotter (defaultSnapshotterName ),
2288
+ containerd .WithNewSnapshot ("snapshot-" + name , image ),
2289
+ containerd .WithNewSpec (oci .WithProcessArgs ("/usr/bin/yes" )),
2290
+ )
2291
+ require .NoError (t , err )
2292
+
2293
+ var stdout1 errorBuffer
2294
+ var stderr1 errorBuffer
2295
+ t1 , err := c .NewTask (ctx , cio .NewCreator (cio .WithStreams (nil , & stdout1 , & stderr1 )))
2296
+ require .NoError (t , err )
2297
+
2298
+ ch , err := t1 .Wait (ctx )
2299
+ require .NoError (t , err )
2300
+
2301
+ err = t1 .Start (ctx )
2302
+ require .NoError (t , err )
2303
+
2304
+ time .Sleep (5 * time .Second )
2305
+
2306
+ err = t1 .CloseIO (ctx , containerd .WithStdinCloser )
2307
+ require .NoError (t , err )
2308
+
2309
+ var stdout2 bytes.Buffer
2310
+ var stderr2 bytes.Buffer
2311
+ t2 , err := c .Task (
2312
+ ctx ,
2313
+ cio .NewAttach (cio .WithStreams (nil , & stdout2 , & stderr2 )),
2314
+ )
2315
+ require .NoError (t , err )
2316
+ assert .Equal (t , t1 .ID (), t2 .ID ())
2317
+
2318
+ err = t2 .Kill (ctx , syscall .SIGKILL )
2319
+ assert .NoError (t , err )
2320
+
2321
+ <- ch
2322
+
2323
+ _ , err = t2 .Delete (ctx )
2324
+ require .NoError (t , err )
2325
+
2326
+ assert .NotEqual (t , "" , stdout2 .String ())
2327
+ }
0 commit comments