Skip to content

Commit 6ab2314

Browse files
committed
io_uring: cancel pending async work if task exits
Normally we cancel all work we track, but for untracked work we could leave the async worker behind until that work completes. This is totally fine, but does leave resources pending after the task is gone until that work completes. Cancel work that this task queued up when it goes away. Signed-off-by: Jens Axboe <[email protected]>
1 parent 3628288 commit 6ab2314

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

fs/io_uring.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,8 @@ static inline void io_req_work_grab_env(struct io_kiocb *req,
925925
}
926926
spin_unlock(&current->fs->lock);
927927
}
928+
if (!req->work.task_pid)
929+
req->work.task_pid = task_pid_vnr(current);
928930
}
929931

930932
static inline void io_req_work_drop_env(struct io_kiocb *req)
@@ -6474,6 +6476,13 @@ static int io_uring_flush(struct file *file, void *data)
64746476
struct io_ring_ctx *ctx = file->private_data;
64756477

64766478
io_uring_cancel_files(ctx, data);
6479+
6480+
/*
6481+
* If the task is going away, cancel work it may have pending
6482+
*/
6483+
if (fatal_signal_pending(current) || (current->flags & PF_EXITING))
6484+
io_wq_cancel_pid(ctx->io_wq, task_pid_vnr(current));
6485+
64776486
return 0;
64786487
}
64796488

0 commit comments

Comments
 (0)