Files
swift-nio-ssl/Sources/NIOOpenSSL
Cory Benfield 8e0aa765e3 Set SSL_MODE_RELEASE_BUFFERS and SSL_MODE_AUTO_RETRY. (#14)
Motivation:

There are two key issues at play here.

Firstly, OpenSSL connections by default hang on to buffers for idle
connections. This isn't really necessary, and setting
SSL_MODE_RELEASE_BUFFERS can save enormous amounts of memory (tens of kb
per connection in some cases).

Secondly, and more profoundly, OpenSSL's default behaviour on SSL_read
is unexpected. In particular, it is possible to get SSL_read to return
SSL_ERROR_WANT_READ in cases where the receive BIO does actually have
an application data record in it, but where a non-application data
record was received first.

Handling that is a tricky case, but it's much easier to ask OpenSSL to
do it for us by just setting SSL_MODE_AUTO_RETRY. This really ought to
be the default behaviour: the fact that it isn't is fairly perplexing.

See https://github.com/openssl/openssl/issues/6234 for more discussion
of SSL_MODE_AUTO_RETRY.

Modifications:

Set SSL_MODE_RELEASE_BUFFERS and SSL_MODE_AUTO_RETRY.

Result:

Less memory usage, fewer subtle bugs.
2018-05-14 21:32:14 +01:00
..