diff --git a/lib/thread/thread.c b/lib/thread/thread.c index b2ae25588..65ddd5bde 100644 --- a/lib/thread/thread.c +++ b/lib/thread/thread.c @@ -1140,6 +1140,12 @@ spdk_get_io_channel(void *io_device) return NULL; } + if (spdk_unlikely(thread->exit)) { + SPDK_ERRLOG("Thread %s is marked as exited\n", thread->name); + pthread_mutex_unlock(&g_devlist_mutex); + return NULL; + } + TAILQ_FOREACH(ch, &thread->io_channels, tailq) { if (ch->dev == dev) { ch->ref++; diff --git a/test/unit/lib/thread/thread.c/thread_ut.c b/test/unit/lib/thread/thread.c/thread_ut.c index 407bfc05d..c3b5d19d3 100644 --- a/test/unit/lib/thread/thread.c/thread_ut.c +++ b/test/unit/lib/thread/thread.c/thread_ut.c @@ -801,6 +801,10 @@ thread_exit(void) thread = spdk_get_thread(); spdk_thread_exit(thread); + /* Thread will not be able to get I/O channel after it is marked as exited. */ + ch = spdk_get_io_channel(&g_device1); + CU_ASSERT(ch == NULL); + poll_threads(); CU_ASSERT(g_destroy_cb_calls == 1);