Skip to content

delay + cancelled runBlocking shutdown loop #586

Closed
@adamp

Description

@adamp

The following code will enter an infinite loop in ThreadEventLoop.shutdown():

runBlocking {
	coroutineContext.cancel()
	delay(1)
}

This loop does not make progress (EventLoop.kt line 337):

// complete processing of all queued tasks
while (processNextEvent() <= 0) { /* spin */ }
// reschedule the rest of delayed tasks
rescheduleAllDelayed()

The heap in EventLoopBase._delayed is not empty and EventLoopBasel._queued was set to CLOSED_EMPTY. isCompleted is true. enqueueImpl(it) on line 133 of EventLoop.kt cannot move the delay into _queued, therefore dequeue()?.run() does nothing. However nextTime is calculated as 0 and returned as a result of checking _delayed.value.peek(), which still exists, causing the loop in shutdown to continue.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions