From 25ae463915f39684419648e5ae8ee1116bde9f4e Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 21 Sep 2017 10:56:45 -0700 Subject: [PATCH 1/3] Listen only on 127.0.0.1 Instead of binding on 0.0.0.0 (which will listen on every interface) let's only listen on localhost. On windows, this both makes the connection Just Work and also prevents the Windows Firewall from blocking the listen (and displaying UI saying it has blocked an application and asking if the user should allow it) --- pkg/resource/deploy/source_eval.go | 2 +- pkg/resource/plugin/host_server.go | 2 +- pkg/util/rpcutil/serve.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/resource/deploy/source_eval.go b/pkg/resource/deploy/source_eval.go index 712461f2a..60e38eeac 100644 --- a/pkg/resource/deploy/source_eval.go +++ b/pkg/resource/deploy/source_eval.go @@ -201,7 +201,7 @@ func newResourceMonitor(reschan chan *evalSourceGoal) (*resmon, error) { return nil, err } - resmon.addr = fmt.Sprintf("0.0.0.0:%d", port) + resmon.addr = fmt.Sprintf("127.0.0.1:%d", port) resmon.done = done return resmon, nil diff --git a/pkg/resource/plugin/host_server.go b/pkg/resource/plugin/host_server.go index 03ddd8bca..19128ba49 100644 --- a/pkg/resource/plugin/host_server.go +++ b/pkg/resource/plugin/host_server.go @@ -44,7 +44,7 @@ func newHostServer(host Host, ctx *Context) (*hostServer, error) { return nil, err } - engine.addr = fmt.Sprintf("0.0.0.0:%d", port) + engine.addr = fmt.Sprintf("127.0.0.1:%d", port) engine.done = done return engine, nil diff --git a/pkg/util/rpcutil/serve.go b/pkg/util/rpcutil/serve.go index 54bc940c0..577ba5b36 100644 --- a/pkg/util/rpcutil/serve.go +++ b/pkg/util/rpcutil/serve.go @@ -30,7 +30,7 @@ func IsBenignCloseErr(err error) bool { // the server is finished, in the case of a successful launch of the RPC server. func Serve(port int, cancel chan bool, registers []func(*grpc.Server) error) (int, chan error, error) { // Listen on a TCP port, but let the kernel choose a free port for us. - lis, err := net.Listen("tcp", ":"+strconv.Itoa(port)) + lis, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(port)) if err != nil { return port, nil, errors.Errorf("failed to listen on TCP port ':%v': %v", port, err) } From fcc81bac2448fa7fb4d95edfc3e8b88c7c5cda67 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 21 Sep 2017 11:49:03 -0700 Subject: [PATCH 2/3] Fix nativeruntime module build on Windows There were two problems: - node-gyp configure was failing because of different shell syntax between windows and *nix. - MSVC 2015 is not smart enough to understand our use of strlen actually results in a constant value and prevents us from using it to create an array, move to a macro based solution. --- sdk/nodejs/runtime/native/binding.gyp | 15 +++++++++++++-- sdk/nodejs/runtime/native/closure.cc | 13 ++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/sdk/nodejs/runtime/native/binding.gyp b/sdk/nodejs/runtime/native/binding.gyp index c909f5090..a4aed0de3 100644 --- a/sdk/nodejs/runtime/native/binding.gyp +++ b/sdk/nodejs/runtime/native/binding.gyp @@ -5,8 +5,19 @@ "sources": [ "closure.cc" ], - "include_dirs": [ - " Lookup(Isolate* isolate, v8::internal::Handle(); } +// MSVC 2015 (which we build with on Windows) does not treat strlen of a literal as a constexpr, +// so we can't use it to intialize our buffer size. So instead, we use sizeof() to compute the +// length, so we need a literal string instead of just a const char*. +#define BAD_PREFIX "[Function:" +#define STRLEN_LITERAL_ONLY(S) (sizeof((S))/sizeof(char) - 1) + Local SerializeFunctionCode(Isolate *isolate, Local func) { // Serialize the code simply by calling toString on the Function. Local toString = Local::Cast( @@ -84,12 +90,11 @@ Local SerializeFunctionCode(Isolate *isolate, Local func) { Local code = Local::Cast(toString->Call(func, 0, nullptr)); // Ensure that the code is a function expression (including arrows), and not a definition, etc. - const char* badprefix = "[Function:"; - size_t badprefixLength = strlen(badprefix); + constexpr size_t badprefixLength = STRLEN_LITERAL_ONLY(BAD_PREFIX); if (code->Length() >= (int)badprefixLength) { char buf[badprefixLength]; code->WriteUtf8(buf, badprefixLength); - if (!strncmp(badprefix, buf, badprefixLength)) { + if (!strncmp(BAD_PREFIX, buf, badprefixLength)) { isolate->ThrowException(Exception::TypeError( String::NewFromUtf8(isolate, "Cannot serialize non-expression functions (such as definitions and generators)"))); @@ -101,6 +106,8 @@ Local SerializeFunctionCode(Isolate *isolate, Local func) { String::Concat(String::NewFromUtf8(isolate, "("), code), String::NewFromUtf8(isolate, ")")); } +#undef BAD_PREFIX +#undef STRLEN_LITERAL_ONLY // SerializeFunction serializes a JavaScript function expression and its associated closure environment. Local SerializeFunction(Isolate *isolate, Local func, From 5470418bea0d123b612b8367b0e1ece6ef1d6e30 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 21 Sep 2017 12:58:46 -0700 Subject: [PATCH 3/3] Disable ANSI Coloring on Windows While these codes can be understood on newer versions of Windows 10 (if we were to set the console properties correctly) in general they do not work and cause garbage to be printed to the screen. For now, just don't colorize output on Windows. --- pkg/diag/colors/windows.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 pkg/diag/colors/windows.go diff --git a/pkg/diag/colors/windows.go b/pkg/diag/colors/windows.go new file mode 100644 index 000000000..7d31d1bd5 --- /dev/null +++ b/pkg/diag/colors/windows.go @@ -0,0 +1,13 @@ +// Copyright 2016-2017, Pulumi Corporation. All rights reserved. + +//+build windows + +package colors + +import ( + "github.com/reconquest/loreley" +) + +func init() { + loreley.Colorize = loreley.ColorizeNever +}