@@ -15,9 +15,9 @@ final class ConnectionFactory: Sendable {
1515 struct SSLContextCache : Sendable {
1616 enum State {
1717 case none
18- case producing( TLSConfiguration , [ CheckedContinuation < NIOSSLContext , any Error > ] )
19- case cached( TLSConfiguration , NIOSSLContext )
20- case failed( TLSConfiguration , any Error )
18+ case producing( [ CheckedContinuation < NIOSSLContext , any Error > ] )
19+ case cached( NIOSSLContext )
20+ case failed( any Error )
2121 }
2222
2323 var state : State = . none
@@ -106,34 +106,17 @@ final class ConnectionFactory: Sendable {
106106 let action = self . sslContextBox. withLockedValue { cache -> Action in
107107 switch cache. state {
108108 case . none:
109- cache. state = . producing( tlsConfiguration , [ continuation] )
109+ cache. state = . producing( [ continuation] )
110110 return . produce
111111
112- case . cached( let cachedTLSConfiguration, let context) :
113- if cachedTLSConfiguration. bestEffortEquals ( tlsConfiguration) {
114- return . succeed( context)
115- } else {
116- cache. state = . producing( tlsConfiguration, [ continuation] )
117- return . produce
118- }
119-
120- case . failed( let cachedTLSConfiguration, let error) :
121- if cachedTLSConfiguration. bestEffortEquals ( tlsConfiguration) {
122- return . fail( error)
123- } else {
124- cache. state = . producing( tlsConfiguration, [ continuation] )
125- return . produce
126- }
127-
128- case . producing( let cachedTLSConfiguration, var continuations) :
112+ case . cached( let context) :
113+ return . succeed( context)
114+ case . failed( let error) :
115+ return . fail( error)
116+ case . producing( var continuations) :
129117 continuations. append ( continuation)
130- if cachedTLSConfiguration. bestEffortEquals ( tlsConfiguration) {
131- cache. state = . producing( cachedTLSConfiguration, continuations)
132- return . wait
133- } else {
134- cache. state = . producing( tlsConfiguration, continuations)
135- return . produce
136- }
118+ cache. state = . producing( continuations)
119+ return . wait
137120 }
138121 }
139122
@@ -143,10 +126,7 @@ final class ConnectionFactory: Sendable {
143126
144127 case . produce:
145128 // TBD: we might want to consider moving this off the concurrent executor
146- self . reportProduceSSLContextResult (
147- Result ( catching: { try NIOSSLContext ( configuration: tlsConfiguration) } ) ,
148- for: tlsConfiguration
149- )
129+ self . reportProduceSSLContextResult ( Result ( catching: { try NIOSSLContext ( configuration: tlsConfiguration) } ) )
150130
151131 case . succeed( let context) :
152132 continuation. resume ( returning: context)
@@ -157,7 +137,7 @@ final class ConnectionFactory: Sendable {
157137 }
158138 }
159139
160- private func reportProduceSSLContextResult( _ result: Result < NIOSSLContext , any Error > , for tlsConfiguration : TLSConfiguration ) {
140+ private func reportProduceSSLContextResult( _ result: Result < NIOSSLContext , any Error > ) {
161141 enum Action {
162142 case fail( any Error , [ CheckedContinuation < NIOSSLContext , any Error > ] )
163143 case succeed( NIOSSLContext , [ CheckedContinuation < NIOSSLContext , any Error > ] )
@@ -172,19 +152,15 @@ final class ConnectionFactory: Sendable {
172152 case . cached, . failed:
173153 return . none
174154
175- case . producing( let cachedTLSConfiguration, let continuations) :
176- if cachedTLSConfiguration. bestEffortEquals ( tlsConfiguration) {
177- switch result {
178- case . success( let context) :
179- cache. state = . cached( cachedTLSConfiguration, context)
180- return . succeed( context, continuations)
181-
182- case . failure( let failure) :
183- cache. state = . failed( cachedTLSConfiguration, failure)
184- return . fail( failure, continuations)
185- }
186- } else {
187- return . none
155+ case . producing( let continuations) :
156+ switch result {
157+ case . success( let context) :
158+ cache. state = . cached( context)
159+ return . succeed( context, continuations)
160+
161+ case . failure( let failure) :
162+ cache. state = . failed( failure)
163+ return . fail( failure, continuations)
188164 }
189165 }
190166 }
0 commit comments