[racket] Memory buildup (leak?) when using `copy-port` with SSL connections.

From: Snyder Pearson (aranhoide at getlantern.org)
Date: Thu Dec 18 03:20:46 EST 2014

I build this simple TLS upgrading proxy[2], which sits in front of a TLS
service and just accepts connections using any SSL/TLS version that Racket
supports and forwards the data to the service using the default TLS version
(why would I need this is a long story :)).

When stress testing this using boom [1], I see significant memory buildup.
This memory is not released when the test finishes.  It only gets reclaimed
when I kill the proxy process.  So I suspect there is some kind of memory
leak going on here.

In principle, the only values constructed on each iteration of the loop are
the SSL connection ports, which I'm closing when |pipe| exits.

Am I using copy-port wrong, or maybe it is itself leaking memory?

This is using Racket v6.1.1 on Ubuntu 14.10.


[1] https://github.com/oxtoacart/boom

[2] Source:

#lang racket

(require openssl)

(define DEBUG #f)

(define (pipe in out)
  (thread (λ ()
             (if DEBUG
               (copy-port in (current-output-port) out)
               (copy-port in out))
             (close-output-port out)
             (close-input-port in))))

(define accept (if DEBUG ssl-accept/enable-break ssl-accept))
(define connect (if DEBUG ssl-connect/enable-break ssl-connect))

(define listener (ssl-listen 62445))
(ssl-load-private-key! listener "pk.pem")
(ssl-load-certificate-chain! listener "cert.pem")

(let loop ()
  (let-values (((from-src to-src) (accept listener)))
      (λ ()
         (let-values (((from-dest to-dest)
                            (connect "localhost" 62444 'tls)))
           (pipe from-src to-dest)
           (pipe from-dest to-src)))))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141218/49d50e12/attachment.html>

Posted on the users mailing list.