diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 2c15d91df8d4c3..3040b3a5b40c9f 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -133,6 +133,10 @@ exports.createSecureContext = function createSecureContext(options, context) { } } + // Do not keep read/write buffers in free list + if (options.singleUse) + c.context.setFreeListLength(0); + return c; }; diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 169e4184fa22b1..d4774312dcad6a 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -862,6 +862,8 @@ exports.connect = function(/* [port, host], options, cb */) { }; options = util._extend(defaults, options || {}); + if (!options.keepAlive) + options.singleUse = true; assert(typeof options.checkServerIdentity === 'function'); diff --git a/src/node_crypto.cc b/src/node_crypto.cc index 9f5ce8992aff3c..fbfa7d961e8e0c 100644 --- a/src/node_crypto.cc +++ b/src/node_crypto.cc @@ -265,6 +265,7 @@ void SecureContext::Initialize(Environment* env, Handle target) { env->SetProtoMethod(t, "loadPKCS12", SecureContext::LoadPKCS12); env->SetProtoMethod(t, "getTicketKeys", SecureContext::GetTicketKeys); env->SetProtoMethod(t, "setTicketKeys", SecureContext::SetTicketKeys); + env->SetProtoMethod(t, "setFreeListLength", SecureContext::SetFreeListLength); env->SetProtoMethod(t, "getCertificate", SecureContext::GetCertificate); env->SetProtoMethod(t, "getIssuer", SecureContext::GetCertificate); @@ -933,6 +934,13 @@ void SecureContext::SetTicketKeys(const FunctionCallbackInfo& args) { } +void SecureContext::SetFreeListLength(const FunctionCallbackInfo& args) { + SecureContext* wrap = Unwrap(args.Holder()); + + wrap->ctx_->freelist_max_len = args[0]->Int32Value(); +} + + void SecureContext::CtxGetter(Local property, const PropertyCallbackInfo& info) { HandleScope scope(info.GetIsolate()); diff --git a/src/node_crypto.h b/src/node_crypto.h index 5e707331cd3185..d407c8f5ff4298 100644 --- a/src/node_crypto.h +++ b/src/node_crypto.h @@ -85,6 +85,8 @@ class SecureContext : public BaseObject { static void LoadPKCS12(const v8::FunctionCallbackInfo& args); static void GetTicketKeys(const v8::FunctionCallbackInfo& args); static void SetTicketKeys(const v8::FunctionCallbackInfo& args); + static void SetFreeListLength( + const v8::FunctionCallbackInfo& args); static void CtxGetter(v8::Local property, const v8::PropertyCallbackInfo& info);