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 84b02a731bef16..7f83e2f759b856 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 b980fb0ab666c8..97a105879f0d6a 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 a623ccbf2637a5..f6069f88410c0b 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);