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.
This commit is contained in:
Johannes Weiss authored and GitHub committed 2020-03-18 18:20:35 +00:00
1 parent 2ad77f9a9b
commit bd4df32a26
1 file changed
+6 -3
+6 -3
View File
@@ -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)