@@ -131,7 +131,7 @@ public class PooledContextFactory : IHttpContextFactory
131
131
private IHttpContextAccessor _httpContextAccessor ;
132
132
133
133
[ ThreadStatic ]
134
- Queue < DefaultHttpContext > _contextPool ;
134
+ static Queue < DefaultHttpContext > _contextPool ;
135
135
136
136
public PooledContextFactory ( ) : this ( httpContextAccessor : null )
137
137
{
@@ -150,23 +150,20 @@ private Queue<DefaultHttpContext> ContextPool
150
150
{
151
151
_contextPool = new Queue < DefaultHttpContext > ( 16 ) ;
152
152
}
153
+
153
154
return _contextPool ;
154
155
}
155
156
}
156
157
157
158
public HttpContext Create ( IFeatureCollection featureCollection )
158
159
{
159
160
var contextPool = ContextPool ;
160
- // locking as ThreadStatic didn't appear to be behaving thread safe via property on coreclr x64
161
- lock ( contextPool )
161
+ if ( contextPool . Count > 0 )
162
162
{
163
- if ( contextPool . Count > 0 )
164
- {
165
- var context = contextPool . Dequeue ( ) ;
166
- // Needs https://github.com/aspnet/HttpAbstractions/pull/501
167
- context . UpdateFeatures ( featureCollection ) ;
168
- return context ;
169
- }
163
+ var context = contextPool . Dequeue ( ) ;
164
+ // Needs https://github.com/aspnet/HttpAbstractions/pull/501
165
+ //context.UpdateFeatures(featureCollection);
166
+ return context ;
170
167
}
171
168
172
169
return new DefaultHttpContext ( featureCollection ) ;
@@ -184,13 +181,10 @@ public void Dispose(HttpContext httpContext)
184
181
if ( context != null )
185
182
{
186
183
var contextPool = ContextPool ;
187
- // locking as ThreadStatic didn't appear to be behaving thread safe via property on coreclr x64
188
- lock ( contextPool )
184
+
185
+ if ( contextPool . Count < 16 )
189
186
{
190
- if ( contextPool . Count < 16 )
191
- {
192
- contextPool . Enqueue ( context ) ;
193
- }
187
+ contextPool . Enqueue ( context ) ;
194
188
}
195
189
}
196
190
}
0 commit comments