core: add finalizer checks for ManagedChannels (#3452)
* core: add finalizer checks for ManagedChannels Cleaning up channels is something users should do. To promote this behavior, add a log message to indicate that the channel has not been properly cleaned. This change users WeakReferences to avoid keeping the channel alive and retaining too much memory. Only the id and the target are kept. Additionally, the lost references are only checked at JVM shutdown and on new channel creation. This is done to avoid Object finalizers. The test added checks to see that the message is logged. Since java does not allow forcing of a GC cycle, this code is best effort, giving up after about a second. A custom log filter is added to hook the log messages and check to see if the correct one is present. Handlers are not used because they are hierarchical, and would be annoying to restore their state after the test. The other tests in the file contribute a lot of bad channels. This is reasonable, because they aren't real channels. However, it does mean that less than half of them are being cleaned up properly. After trying to fix a few, it is too hard to do. It would only serve to massively complicate the tests. Instead, this code just keeps track of how many it wasn't able to clean up, and ignores them for the test. They are still logged, because really they should be closed.
Loading
Please sign in to comment