Skip to content

Commit 357dd88

Browse files
authored
Clarify that we don't hop ELs in our callbacks (#526)
1 parent fa7b4a5 commit 357dd88

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Sources/NIOSSL/CustomPrivateKey.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ extension SSLConnection {
156156
inputBytes.writeBytes(`in`)
157157

158158
let result = customKey.sign(channel: channel, algorithm: wrappedAlgorithm, data: inputBytes)
159-
result.whenComplete { signingResult in
159+
result.hop(to: channel.eventLoop).assumeIsolated().whenComplete { signingResult in
160160
self.storeCustomPrivateKeyResult(signingResult, channel: channel)
161161
}
162162

@@ -178,7 +178,7 @@ extension SSLConnection {
178178
inputBytes.writeBytes(`in`)
179179

180180
let result = customKey.decrypt(channel: channel, data: inputBytes)
181-
result.whenComplete { decryptionResult in
181+
result.hop(to: channel.eventLoop).assumeIsolated().whenComplete { decryptionResult in
182182
self.storeCustomPrivateKeyResult(decryptionResult, channel: channel)
183183
}
184184

@@ -207,7 +207,7 @@ extension SSLConnection {
207207
// When we complete here we need to set our result state, and then ask to respin the handshake.
208208
// If we can't respin the handshake because we've dropped the parent handler, that's fine, no harm no foul.
209209
// For that reason, we tolerate both the verify manager and the parent handler being nil.
210-
channel.eventLoop.execute {
210+
channel.eventLoop.assumeIsolated().execute {
211211
precondition(self.customPrivateKeyResult == nil)
212212
self.customPrivateKeyResult = result
213213
self.parentHandler?.resumeHandshake()

Sources/NIOSSL/SSLCallbacks.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,10 +333,10 @@ extension CustomContextManager {
333333
let promise = eventLoop.makePromise(of: NIOSSLContextConfigurationOverride.self)
334334
self.callback(values, promise)
335335

336-
promise.futureResult.whenComplete { result in
336+
promise.futureResult.assumeIsolated().whenComplete { result in
337337
// Ensure we execute any completion on the next event loop tick
338338
// This ensures that we suspend before calling resume
339-
eventLoop.execute {
339+
eventLoop.assumeIsolated().execute {
340340
connection.parentContext.customContextManager?.state = .complete(result)
341341
connection.parentHandler?.resumeHandshake()
342342
}
@@ -445,11 +445,11 @@ extension CustomVerifyManager {
445445

446446
// We need to attach our "do the thing" callback. This will always invoke the "ask me again" API, and it will do so in a separate
447447
// event loop tick to avoid awkward re-entrancy with this method.
448-
promise.futureResult.whenComplete { result in
448+
promise.futureResult.assumeIsolated().whenComplete { result in
449449
// When we complete here we need to set our result state, and then ask to respin certificate verification.
450450
// If we can't respin verification because we've dropped the parent handler, that's fine, no harm no foul.
451451
// For that reason, we tolerate both the verify manager and the parent handler being nil.
452-
eventLoop.execute {
452+
eventLoop.assumeIsolated().execute {
453453
// Note that we don't close over self here: that's to deal with the fact that this is a struct, and we don't want to
454454
// escape the mutable ownership of self.
455455
precondition(

0 commit comments

Comments
 (0)