Subject: | Memory leak at close time |
I've been investigating a memory leak of a long-running HTTPS process as part of https://rt.cpan.org/Ticket/Display.html?id=124927. I suspect the issue is within IO::Socket::SSL. This is against version 2.056.
If I regularly poll HTTPS servers in a long-running process, then the memory grows linearly without bounds over time. Analysis with Devel::MAT has so far revealed this is unbounded growth of the
my %SSL_OBJECT;
hash in IO/Socket/SSL.pm.
By inserting some `print STDERR` statements in key places, it appears that every time the poll interval comes up, it finds that the old connection has been closed by the server, so it has to be destroyed and recreated. The line
sub stop_SSL
1430: delete ${*$self}{_SSL_object};
runs, deleting the _SSL_object key from the instance, so that in a moment later when the SSL socket object itself is destroyed, the line
sub DESTROY
2010 my $ssl = ${*$self}{_SSL_object} or return;
finds nothing of interest, so returns before it gets to
2011 delete $SSL_OBJECT{$ssl};
This causes an unbounded accumulation of keys in %SSL_OBJECT, and so the process memory grows indefinitely.
Another small observation is that this seems very related to connection setup/close, because if I poll at sufficiently small interval (say, 1 second) then the servers I connect to don't get bored and timeout the connections, so sockets get reused. In that case, no new SSL connections need creating and old ones destroying, and the memory usage remains flat.
--
Paul Evans