mirror of
https://github.com/aspnet/JavaScriptServices.git
synced 2025-12-22 17:47:53 +00:00
Performance fix
- Usage of resolved loopback IP address instead of 'localhost' Addresses #1588
This commit is contained in:
committed by
Steve Sanderson
parent
7f550fb469
commit
78f7dccfab
@@ -121,8 +121,8 @@
|
|||||||
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
|
var parsedArgs = ArgsUtil_1.parseArgs(process.argv);
|
||||||
var requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
|
var requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
|
||||||
server.listen(requestedPortOrZero, 'localhost', function () {
|
server.listen(requestedPortOrZero, 'localhost', function () {
|
||||||
// Signal to HttpNodeHost which port it should make its HTTP connections on
|
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
|
||||||
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port ' + server.address().port + '\]');
|
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + server.address().address + '} port ' + server.address().port + '\]');
|
||||||
// Signal to the NodeServices base class that we're ready to accept invocations
|
// Signal to the NodeServices base class that we're ready to accept invocations
|
||||||
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
|
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
|||||||
/// <seealso cref="Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance" />
|
/// <seealso cref="Microsoft.AspNetCore.NodeServices.HostingModels.OutOfProcessNodeInstance" />
|
||||||
internal class HttpNodeInstance : OutOfProcessNodeInstance
|
internal class HttpNodeInstance : OutOfProcessNodeInstance
|
||||||
{
|
{
|
||||||
private static readonly Regex PortMessageRegex =
|
private static readonly Regex EndpointMessageRegex =
|
||||||
new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port (\d+)\]$");
|
new Regex(@"^\[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {(.*?)} port (\d+)\]$");
|
||||||
|
|
||||||
private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
|
private static readonly JsonSerializerSettings jsonSerializerSettings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
@@ -32,7 +32,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
|||||||
|
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
private int _portNumber;
|
private string _endpoint;
|
||||||
|
|
||||||
public HttpNodeInstance(NodeServicesOptions options, int port = 0)
|
public HttpNodeInstance(NodeServicesOptions options, int port = 0)
|
||||||
: base(
|
: base(
|
||||||
@@ -63,7 +63,7 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
|||||||
{
|
{
|
||||||
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
|
var payloadJson = JsonConvert.SerializeObject(invocationInfo, jsonSerializerSettings);
|
||||||
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
|
var payload = new StringContent(payloadJson, Encoding.UTF8, "application/json");
|
||||||
var response = await _client.PostAsync("http://localhost:" + _portNumber, payload, cancellationToken);
|
var response = await _client.PostAsync(_endpoint, payload, cancellationToken);
|
||||||
|
|
||||||
if (!response.IsSuccessStatusCode)
|
if (!response.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
@@ -111,13 +111,19 @@ namespace Microsoft.AspNetCore.NodeServices.HostingModels
|
|||||||
|
|
||||||
protected override void OnOutputDataReceived(string outputData)
|
protected override void OnOutputDataReceived(string outputData)
|
||||||
{
|
{
|
||||||
// Watch for "port selected" messages, and when observed, store the port number
|
// Watch for "port selected" messages, and when observed,
|
||||||
|
// store the IP (IPv4/IPv6) and port number
|
||||||
// so we can use it when making HTTP requests. The child process will always send
|
// so we can use it when making HTTP requests. The child process will always send
|
||||||
// one of these messages before it sends a "ready for connections" message.
|
// one of these messages before it sends a "ready for connections" message.
|
||||||
var match = _portNumber != 0 ? null : PortMessageRegex.Match(outputData);
|
var match = string.IsNullOrEmpty(_endpoint) ? EndpointMessageRegex.Match(outputData) : null;
|
||||||
if (match != null && match.Success)
|
if (match != null && match.Success)
|
||||||
{
|
{
|
||||||
_portNumber = int.Parse(match.Groups[1].Captures[0].Value);
|
var port = int.Parse(match.Groups[2].Captures[0].Value);
|
||||||
|
var resolvedIpAddress = match.Groups[1].Captures[0].Value;
|
||||||
|
|
||||||
|
//IPv6 must be wrapped with [] brackets
|
||||||
|
resolvedIpAddress = resolvedIpAddress == "::1" ? $"[{resolvedIpAddress}]" : resolvedIpAddress;
|
||||||
|
_endpoint = $"http://{resolvedIpAddress}:{port}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ const server = http.createServer((req, res) => {
|
|||||||
const parsedArgs = parseArgs(process.argv);
|
const parsedArgs = parseArgs(process.argv);
|
||||||
const requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
|
const requestedPortOrZero = parsedArgs.port || 0; // 0 means 'let the OS decide'
|
||||||
server.listen(requestedPortOrZero, 'localhost', function () {
|
server.listen(requestedPortOrZero, 'localhost', function () {
|
||||||
// Signal to HttpNodeHost which port it should make its HTTP connections on
|
// Signal to HttpNodeHost which loopback IP address (IPv4 or IPv6) and port it should make its HTTP connections on
|
||||||
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on port ' + server.address().port + '\]');
|
console.log('[Microsoft.AspNetCore.NodeServices.HttpNodeHost:Listening on {' + server.address().address + '} port ' + server.address().port + '\]');
|
||||||
|
|
||||||
// Signal to the NodeServices base class that we're ready to accept invocations
|
// Signal to the NodeServices base class that we're ready to accept invocations
|
||||||
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
|
console.log('[Microsoft.AspNetCore.NodeServices:Listening]');
|
||||||
|
|||||||
Reference in New Issue
Block a user