Skip to content

[Backport 2.x] Fix Dispatchers.IO starvation deadlock in notification send path - #1251

Open
opensearch-ci-bot wants to merge 1 commit into
opensearch-project:2.xfrom
opensearch-ci-bot:backport/backport-1248-to-2.x
Open

[Backport 2.x] Fix Dispatchers.IO starvation deadlock in notification send path#1251
opensearch-ci-bot wants to merge 1 commit into
opensearch-project:2.xfrom
opensearch-ci-bot:backport/backport-1248-to-2.x

Conversation

@opensearch-ci-bot

Copy link
Copy Markdown
Contributor

Backport 70804cb from #1248.

…nsearch-project#1248)

* Fix Dispatchers.IO starvation deadlock in notification send path

SendMessageActionHelper used runBlocking inside code already running on
a Dispatchers.IO coroutine (PluginBaseAction launches every transport
request on CoroutineScope(Dispatchers.IO)). The parent coroutine parked
its dispatcher thread while awaiting child async(Dispatchers.IO) sends
that need threads from the same pool.

Under sustained concurrent sends to a slow destination (e.g. a webhook
that times out), parents eventually occupy all 64 Dispatchers.IO slots.
At that point no child can ever be scheduled and no parent can ever
complete: a permanent dispatcher deadlock. Because all Notifications
transport actions share the same scope, every plugin API (e.g.
GET /_plugins/_notifications/features) hangs until the node is
restarted.

Replace runBlocking with structured concurrency: the send-path
functions become suspend functions and use coroutineScope { ... }
+ awaitAll(), so waiting parents suspend and release their dispatcher
threads instead of parking them. All call chains already terminate in
suspend transport-action methods, so no additional bridging is needed.

Reproduced by flooding 200 concurrent send requests at a webhook
channel that responds after 30s: before this change the node's
notifications APIs deadlock permanently (64 threads parked in
runBlocking at sendMessagesInParallel, zero threads performing sends);
after this change all sends complete and APIs remain responsive.

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>

* Add comment explaining why sendMessageToChannel is a suspend function

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>

---------

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
(cherry picked from commit 70804cb)
Signed-off-by: opensearch-ci-bot <opensearch-infra@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants