| 343 | } |
| 344 | |
| 345 | func (m *taskManager) AttachIO(_ context.Context, taskID, execID string, proxy IOProxy) error { |
| 346 | m.mu.Lock() |
| 347 | defer m.mu.Unlock() |
| 348 | |
| 349 | proc, err := m.findProc(taskID, execID) |
| 350 | if err != nil { |
| 351 | return err |
| 352 | } |
| 353 | |
| 354 | initDone, copyDone := proxy.start(proc) |
| 355 | proc.proxy = proxy |
| 356 | proc.ioCopyDone = copyDone |
| 357 | |
| 358 | // This must be in a goroutine. Otherwise, sending to initDone channel blocks forever. |
| 359 | go func() { |
| 360 | e := <-initDone |
| 361 | if e != nil { |
| 362 | proc.logger.Error("failed to initialize an io proxy") |
| 363 | proxy.Close() |
| 364 | } |
| 365 | }() |
| 366 | go monitorIO(copyDone, proc) |
| 367 | |
| 368 | return nil |
| 369 | } |
| 370 | |
| 371 | func monitorIO(done <-chan error, proc *vmProc) { |
| 372 | <-done |