@@ -15,9 +15,9 @@ final class ConnectionFactory: Sendable {
15
15
struct SSLContextCache : Sendable {
16
16
enum State {
17
17
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 )
21
21
}
22
22
23
23
var state : State = . none
@@ -106,34 +106,17 @@ final class ConnectionFactory: Sendable {
106
106
let action = self . sslContextBox. withLockedValue { cache -> Action in
107
107
switch cache. state {
108
108
case . none:
109
- cache. state = . producing( tlsConfiguration , [ continuation] )
109
+ cache. state = . producing( [ continuation] )
110
110
return . produce
111
111
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) :
129
117
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
137
120
}
138
121
}
139
122
@@ -143,10 +126,7 @@ final class ConnectionFactory: Sendable {
143
126
144
127
case . produce:
145
128
// 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) } ) )
150
130
151
131
case . succeed( let context) :
152
132
continuation. resume ( returning: context)
@@ -157,7 +137,7 @@ final class ConnectionFactory: Sendable {
157
137
}
158
138
}
159
139
160
- private func reportProduceSSLContextResult( _ result: Result < NIOSSLContext , any Error > , for tlsConfiguration : TLSConfiguration ) {
140
+ private func reportProduceSSLContextResult( _ result: Result < NIOSSLContext , any Error > ) {
161
141
enum Action {
162
142
case fail( any Error , [ CheckedContinuation < NIOSSLContext , any Error > ] )
163
143
case succeed( NIOSSLContext , [ CheckedContinuation < NIOSSLContext , any Error > ] )
@@ -172,19 +152,15 @@ final class ConnectionFactory: Sendable {
172
152
case . cached, . failed:
173
153
return . none
174
154
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)
188
164
}
189
165
}
190
166
}
0 commit comments