Description
Describe the bug
The System.ServiceModel.InstanceContext
type has an internal WmiChannels
property, which holds a list of IChannel
instances.
We observed increased memory usage, and upon analysis of memory dump, we found about 50gb of memory retained by that list. All observed channels are in faulted state, and our application automatically recycles a channel when it detects that a channel became faulty. Browsing the code in this repository, it appears that the list only grows. Channels are added in this line of code, but I could not find any place where channels are removed.
To Reproduce
- Create a service that uses a single
InstanceContext
for the entire application, as documented here. - Create some WCF endpoint that times out whenever it receives a call (make it sleep for 10s). This is required to put the client channel in faulted state.
- Create an infinite loop that creates a channel with a client timeout of 2s, calls the above endpoint it and ignores the timeout exception. Make sure your channel creation options trigger this line of code.
The bug should repro even if the faulted channel is disposed. Just make sure the reference is cleared (i.e. reuse the reference on each iteration of the loop).
Expected behavior
As the loop executes, memory usage should eventually stabilize. It must not grow forever.