Index: sys/dev/cxgbe/tom/t4_cpl_io.c =================================================================== --- sys/dev/cxgbe/tom/t4_cpl_io.c +++ sys/dev/cxgbe/tom/t4_cpl_io.c @@ -2211,6 +2211,7 @@ } toep->aiotx_task_active = false; SOCKBUF_UNLOCK(&so->so_snd); + wakeup(&toep->aiotx_task_active); CURVNET_RESTORE(); free_toepcb(toep); @@ -2248,8 +2249,20 @@ sb = &so->so_snd; SOCKBUF_LOCK(sb); - if (!aio_cancel_cleared(job)) + if (!aio_cancel_cleared(job)) { TAILQ_REMOVE(&toep->aiotx_jobq, job, list); + + /* + * Wait for any pending task to run if the jobq is now + * empty as this job is holding the reference to the + * socket that the task is depending on. + */ + if (TAILQ_EMPTY(&toep->aiotx_jobq)) { + while (toep->aiotx_task_active) + mtx_sleep(&toep->aiotx_task_active, + SOCKBUF_MTX(sb), 0, "aiotxcan", 0); + } + } SOCKBUF_UNLOCK(sb); ab = job->backend1;