From bd4df32a260e88468989264895db7ca86a2ff0d7 Mon Sep 17 00:00:00 2001 From: Johannes Weiss Date: Wed, 18 Mar 2020 18:20:35 +0000 Subject: [PATCH] downgrade 'schedule after shutdown' to printing error (#1454) Motivation: Since #1395, we crash when something is scheduled to an already shutdown EventLoop. That's a good intent (#1383) but we feel it's a little too risky right now. Modifications: Print an ERROR instead of just crashing. Result: Fewer crashes. --- Sources/NIO/SelectableEventLoop.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Sources/NIO/SelectableEventLoop.swift b/Sources/NIO/SelectableEventLoop.swift index a0ea7e843..5f0e3f0ae 100644 --- a/Sources/NIO/SelectableEventLoop.swift +++ b/Sources/NIO/SelectableEventLoop.swift @@ -254,15 +254,18 @@ internal final class SelectableEventLoop: EventLoop { internal func _schedule0(_ task: ScheduledTask) throws { if self.inEventLoop { precondition(self._validInternalStateToScheduleTasks, - "cannot schedule tasks on an EventLoop that has already shut down") + "BUG IN NIO (please report): EventLoop is shutdown, yet we're on the EventLoop.") self._tasksLock.withLockVoid { self._scheduledTasks.push(task) } } else { self.externalStateLock.withLockVoid { - precondition(self._validExternalStateToScheduleTasks, - "cannot schedule tasks on an EventLoop that has already shut down") + guard self._validExternalStateToScheduleTasks else { + print("ERROR: Cannot schedule tasks on an EventLoop that has already shut down. " + + "This will be upgraded to a forced crash in future SwiftNIO versions.") + return + } self._tasksLock.withLockVoid { self._scheduledTasks.push(task)