From 6e72fd3e9306ad1a71514482f0c010de67baf8fb Mon Sep 17 00:00:00 2001 From: JeremyTCD Date: Sat, 22 Feb 2020 12:05:38 +0800 Subject: [PATCH 1/3] Fixed Stream return value getting disposed --- .../OutOfProcess/Http/HttpNodeJSService.cs | 12 ++++----- .../HttpNodeJSServiceIntegrationTests.cs | 25 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpNodeJSService.cs b/src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpNodeJSService.cs index b968052..58cd5eb 100644 --- a/src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpNodeJSService.cs +++ b/src/NodeJS/NodeJSServiceImplementations/OutOfProcess/Http/HttpNodeJSService.cs @@ -104,15 +104,15 @@ public HttpNodeJSService(IOptions outOfProcess return (true, (T)(object)result); } - using (Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false)) + if (typeof(T) == typeof(Stream)) { - if (typeof(T) == typeof(Stream)) - { - return (true, (T)(object)stream); - } + Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false); + return (true, (T)(object)stream); // User's reponsibility to handle disposal + } + using (Stream stream = await httpResponseMessage.Content.ReadAsStreamAsync().ConfigureAwait(false)) + { T result = await _jsonService.DeserializeAsync(stream, cancellationToken).ConfigureAwait(false); - return (true, result); } } diff --git a/test/NodeJS/HttpNodeJSServiceIntegrationTests.cs b/test/NodeJS/HttpNodeJSServiceIntegrationTests.cs index 676f479..f60fd5c 100644 --- a/test/NodeJS/HttpNodeJSServiceIntegrationTests.cs +++ b/test/NodeJS/HttpNodeJSServiceIntegrationTests.cs @@ -983,6 +983,31 @@ public async void AllInvokeMethods_HandleHttpClientErrorsSuchAsMalformedRequests } } + [Fact] + public async void AllInvokeMethodsThatReturnAValue_HandleStreamReturnType() + { + // Arrange + const string dummyData = "dummyData"; + string dummyModule = $@"var Readable = require('stream').Readable; +module.exports = (callback) => {{ + var stream = new Readable(); + stream.push('{dummyData}'); + stream.push(null); + + callback(null, stream); +}}"; + HttpNodeJSService testSubject = CreateHttpNodeJSService(); + + // Act + using (Stream resultStream = await testSubject.InvokeFromStringAsync(dummyModule).ConfigureAwait(false)) + using (var streamReader = new StreamReader(resultStream)) + { + // Assert + string result = streamReader.ReadToEnd(); + Assert.Equal(dummyData, result); + } + } + /// /// Specify for access to all logging output. /// From 161d6c9c6a05a5143529ed040e9a6f1bc038ca9e Mon Sep 17 00:00:00 2001 From: JeremyTCD Date: Sat, 22 Feb 2020 12:08:59 +0800 Subject: [PATCH 2/3] Added release 5.3.2. --- Changelog.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Changelog.md b/Changelog.md index a324dbd..cfa2498 100644 --- a/Changelog.md +++ b/Changelog.md @@ -3,7 +3,11 @@ This project uses [semantic versioning](http://semver.org/spec/v2.0.0.html). Ref *[Semantic Versioning in Practice](https://www.jering.tech/articles/semantic-versioning-in-practice)* for an overview of semantic versioning. -## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/5.3.1...HEAD) +## [Unreleased](https://github.com/JeringTech/Javascript.NodeJS/compare/5.3.2...HEAD) + +## [5.3.2](https://github.com/JeringTech/Javascript.NodeJS/compare/5.3.1...5.3.2) - Feb 22, 2020 +### Fixes +- `HttpNodeJSService` no longer disposes `Stream`s before returning them. ([#73](https://github.com/JeringTech/Javascript.NodeJS/pull/73)). ## [5.3.1](https://github.com/JeringTech/Javascript.NodeJS/compare/5.3.0...5.3.1) - Feb 12, 2020 ### Fixes From 37acd8ad168aa269d9b500bc224baf6fd3573b67 Mon Sep 17 00:00:00 2001 From: JeremyTCD Date: Sat, 22 Feb 2020 13:52:53 +0800 Subject: [PATCH 3/3] Bumped Yarn.MSBuild to fix yarn permissions on mac - https://github.com/natemcmaster/Yarn.MSBuild/pull/25 --- .../Jering.Javascript.NodeJS.Performance.csproj | 2 +- perf/NodeJS/packages.lock.json | 6 +++--- src/NodeJS/Jering.Javascript.NodeJS.csproj | 6 +++--- src/NodeJS/packages.lock.json | 12 ++++++------ test/NodeJS/Jering.Javascript.NodeJS.Tests.csproj | 2 +- test/NodeJS/packages.lock.json | 12 ++++++------ 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/perf/NodeJS/Jering.Javascript.NodeJS.Performance.csproj b/perf/NodeJS/Jering.Javascript.NodeJS.Performance.csproj index 9f66053..d1d2202 100644 --- a/perf/NodeJS/Jering.Javascript.NodeJS.Performance.csproj +++ b/perf/NodeJS/Jering.Javascript.NodeJS.Performance.csproj @@ -13,7 +13,7 @@ - + diff --git a/perf/NodeJS/packages.lock.json b/perf/NodeJS/packages.lock.json index 80f9fef..8052af5 100644 --- a/perf/NodeJS/packages.lock.json +++ b/perf/NodeJS/packages.lock.json @@ -32,9 +32,9 @@ }, "Yarn.MSBuild": { "type": "Direct", - "requested": "[1.16.0, )", - "resolved": "1.16.0", - "contentHash": "JzrCeiEMGjkw+z4JvOeZMWmhJF7YI7KDPXglg7PRtFqqBarLFiwGXsMPmiJQ+tXxFNfdBX8KmfDX0KT8htZjZw==" + "requested": "[1.22.0, )", + "resolved": "1.22.0", + "contentHash": "+uECXuuZ+8kjNR8bF6Y8wyKiDbrI/MSX9VTuE0q1GcRm13vU7IZl4WUfXSb/3aHmxsDsWGZxktfEnwe2YWgugg==" }, "BenchmarkDotNet.Annotations": { "type": "Transitive", diff --git a/src/NodeJS/Jering.Javascript.NodeJS.csproj b/src/NodeJS/Jering.Javascript.NodeJS.csproj index b063eaf..c5aa956 100644 --- a/src/NodeJS/Jering.Javascript.NodeJS.csproj +++ b/src/NodeJS/Jering.Javascript.NodeJS.csproj @@ -53,7 +53,7 @@ runtime; build; native; contentfiles; analyzers - + compile; build; native; contentfiles; analyzers; buildtransitive @@ -86,11 +86,11 @@ So we must specify both. This way if we are multi-targeting, JavascriptBuild runs once, before DispatchToInnerBuilds after which inputs == outputs. If we aren't multi-targeting, JavascriptBuild runs before PreBuildEvent. --> - + - + diff --git a/src/NodeJS/packages.lock.json b/src/NodeJS/packages.lock.json index 40d0182..b6116f8 100644 --- a/src/NodeJS/packages.lock.json +++ b/src/NodeJS/packages.lock.json @@ -93,9 +93,9 @@ }, "Yarn.MSBuild": { "type": "Direct", - "requested": "[1.16.0, )", - "resolved": "1.16.0", - "contentHash": "JzrCeiEMGjkw+z4JvOeZMWmhJF7YI7KDPXglg7PRtFqqBarLFiwGXsMPmiJQ+tXxFNfdBX8KmfDX0KT8htZjZw==" + "requested": "[1.22.0, )", + "resolved": "1.22.0", + "contentHash": "+uECXuuZ+8kjNR8bF6Y8wyKiDbrI/MSX9VTuE0q1GcRm13vU7IZl4WUfXSb/3aHmxsDsWGZxktfEnwe2YWgugg==" }, "Microsoft.AspNetCore.Hosting.Server.Abstractions": { "type": "Transitive", @@ -640,9 +640,9 @@ }, "Yarn.MSBuild": { "type": "Direct", - "requested": "[1.16.0, )", - "resolved": "1.16.0", - "contentHash": "JzrCeiEMGjkw+z4JvOeZMWmhJF7YI7KDPXglg7PRtFqqBarLFiwGXsMPmiJQ+tXxFNfdBX8KmfDX0KT8htZjZw==" + "requested": "[1.22.0, )", + "resolved": "1.22.0", + "contentHash": "+uECXuuZ+8kjNR8bF6Y8wyKiDbrI/MSX9VTuE0q1GcRm13vU7IZl4WUfXSb/3aHmxsDsWGZxktfEnwe2YWgugg==" }, "Microsoft.AspNetCore.Hosting.Server.Abstractions": { "type": "Transitive", diff --git a/test/NodeJS/Jering.Javascript.NodeJS.Tests.csproj b/test/NodeJS/Jering.Javascript.NodeJS.Tests.csproj index 9cdb81a..b8711b7 100644 --- a/test/NodeJS/Jering.Javascript.NodeJS.Tests.csproj +++ b/test/NodeJS/Jering.Javascript.NodeJS.Tests.csproj @@ -36,7 +36,7 @@ - + diff --git a/test/NodeJS/packages.lock.json b/test/NodeJS/packages.lock.json index 9a9cd28..6b1485c 100644 --- a/test/NodeJS/packages.lock.json +++ b/test/NodeJS/packages.lock.json @@ -92,9 +92,9 @@ }, "Yarn.MSBuild": { "type": "Direct", - "requested": "[1.16.0, )", - "resolved": "1.16.0", - "contentHash": "JzrCeiEMGjkw+z4JvOeZMWmhJF7YI7KDPXglg7PRtFqqBarLFiwGXsMPmiJQ+tXxFNfdBX8KmfDX0KT8htZjZw==" + "requested": "[1.22.0, )", + "resolved": "1.22.0", + "contentHash": "+uECXuuZ+8kjNR8bF6Y8wyKiDbrI/MSX9VTuE0q1GcRm13vU7IZl4WUfXSb/3aHmxsDsWGZxktfEnwe2YWgugg==" }, "Castle.Core": { "type": "Transitive", @@ -1023,9 +1023,9 @@ }, "Yarn.MSBuild": { "type": "Direct", - "requested": "[1.16.0, )", - "resolved": "1.16.0", - "contentHash": "JzrCeiEMGjkw+z4JvOeZMWmhJF7YI7KDPXglg7PRtFqqBarLFiwGXsMPmiJQ+tXxFNfdBX8KmfDX0KT8htZjZw==" + "requested": "[1.22.0, )", + "resolved": "1.22.0", + "contentHash": "+uECXuuZ+8kjNR8bF6Y8wyKiDbrI/MSX9VTuE0q1GcRm13vU7IZl4WUfXSb/3aHmxsDsWGZxktfEnwe2YWgugg==" }, "Castle.Core": { "type": "Transitive",