Fix possible infinite recursive loop when deregistering from the Selector throws an error while in close0 method

This commit is contained in:
Norman Maurer committed 2017-08-16 19:36:50 +02:00
1 parent 1619c3d7c8
commit 4f91fe3f65
2 files changed
+10 -12

No files matched your search

+6 -12
View File
@@ -1116,7 +1116,12 @@ class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
return
}
safeDeregister()
interestedEvent = .none
do {
try selectableEventLoop.deregister(channel: self)
} catch let err {
pipeline.fireErrorCaught0(error: err)
}
do {
try socket.close()
@@ -1288,17 +1293,6 @@ class BaseSocketChannel<T : BaseSocket> : SelectableChannel, ChannelCore {
return interestedEvent == .write || interestedEvent == .all
}
// Methods only used from within this class
private func safeDeregister() {
interestedEvent = .none
do {
try selectableEventLoop.deregister(channel: self)
} catch let err {
pipeline.fireErrorCaught0(error: err)
close0(error: err, promise: nil)
}
}
private func safeReregister(interested: IOEvent) {
guard !closed else {
interestedEvent = .none
+4
View File
@@ -130,6 +130,10 @@ final class SelectableEventLoop : EventLoop {
func deregister<C: SelectableChannel>(channel: C) throws {
assert(inEventLoop)
guard !closed else {
// Its possible the EventLoop was closed before we were able to call deregister, so just return in this case as there is no harm.
return
}
try selector.deregister(selectable: channel.selectable)
}