Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Node memory leak (#2313) #2320

Merged
merged 1 commit into from
Jan 17, 2018
Merged

Fixing Node memory leak (#2313) #2320

merged 1 commit into from
Jan 17, 2018

Conversation

mathewc
Copy link
Member

@mathewc mathewc commented Jan 17, 2018

Fix for #2313.


var bindings = new Dictionary<string, object>();
var bind = (ScriptFunc)(p =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bind function goes away. In working on this fix, I was trying to minimize the bi-directional calls between .NET and Node (which is the source of the memory leaks). In this case, rather than having Node call back into .NET to process binding results, I just return them as part of a structured function result, and allow them to be processed after control returns back to .NET.

@@ -348,70 +351,14 @@ protected override void Dispose(bool disposing)

private async Task<Dictionary<string, object>> CreateScriptExecutionContextAsync(object input, DataType dataType, TraceWriter traceWriter, FunctionInvocationContext invocationContext)
{
// create a TraceWriter wrapper that can be exposed to Node.js
var log = (ScriptFunc)(p =>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log and metric functions I pushed out into static factory methods, to prevent regressions. The factory functions take WeakReferences, so we won't accidentally regress things going forward.

}
context.bind(values, function (err) {
Copy link
Member Author

@mathewc mathewc Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we were calling back into .NET here to allow it to process these binding values. We were doing this to enable us to capture any context.bindings[xxx] values the user code might have set. Edge.JS interop won't capture new properties added to objects/dictionaries.

With my changes, rather than call back into .NET to copy these values into the bindings collection, we just return the values as part of the response.

@mathewc mathewc changed the title Fixing memory leak (#2313) Fixing Node memory leak (#2313) Jan 17, 2018
@mathewc mathewc requested a review from brettsam January 17, 2018 17:32
Copy link
Member

@fabiocav fabiocav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

}
}

return Task.FromResult<object>(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Use Task.CompletedTask

Copy link
Member Author

@mathewc mathewc Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't work because this is a Task<object> not Task

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Just looked at this line (not the signature) and assumed this was just using an old pattern from the existing code.

@mathewc mathewc merged commit e991260 into v1.x Jan 17, 2018
Copy link
Member

@brettsam brettsam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚢

@mathewc mathewc deleted the mem_leak branch January 23, 2018 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants