[SignalR] Avoid initial memory allocation in ChannelBasedSemaphore #47588
Labels
area-signalr
Includes: SignalR clients and servers
design-proposal
This issue represents a design proposal for a different issue, linked in the description
Summary
The initial memory allocation should be avoided in
ChannelBasedSemaphore
Motivation and goals
Some developers could just give
HubConnectionContextOptions.MaximumParallelInvocations
a large value (such asint.MaxValue
) to ensure their single client can make as many parallel invocations as possible.Unfortunately ,
ChannelBasedSemaphore
will always allocate'enough'
memory according toHubConnectionContextOptions.MaximumParallelInvocations
on first invocation, even if there is only one invocation here, and the whole program may crash or have high cpu and memory usage without a friendly warning. This behavior increases the costs of diagnostics.This is a sample message for an event about this error in
Event Viewer
in Win10By the way, will this cause an inconsistent result for available invocation quotas? I didn't see any
Release
corresponding the result ofTryAcquire
.In scope
This is my immature idea. Maybe we can use the
Interlocked
to implementTryAcquire
, and use the combination ofInterlocked
andChannel
forWaitAsync
andRunAsync
?The text was updated successfully, but these errors were encountered: