A little background:
I'm working on a Windows program that uses RPC to communicate over a network. Network connections are made and disconnected continuously. The RPC calls are synchronous, but there are more than one client threads operating simultaneously. The programs are symmetric - that is to say, both sides act as client and server, and are running the exact same software. It's implemented in C++ using the standard Windows API.
The problem:
The number of thread handles reported by Process Explorer increases over time. It appears that threads are made by the RPC runtime to handle the requests, but that the handles are not always cleaned up when the thread is reclaimed.
The number increases especially when there is a lot of data being transmitted, or when there are many calls happening simultaneously (these two factors come hand-in-hand, and I am unsure which is relevant).
An active server can build up several thousand unused thread handles over the course of a few days, while never using more than 20 threads at any time.
The question:
What can I do to keep the handle count from mounting, because I believe it may be causing stability issues at customer sites?