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

[win32] Explicitly close rx pipe when closing wallet #1679

Merged
merged 4 commits into from
Oct 9, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions app/main_dev/launch.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const logger = createLogger(debug);

let dcrdPID;
let dcrwPID;
let dcrwPipeRx;

let dcrwPort;

Expand All @@ -38,6 +39,13 @@ export const closeDCRW = () => {
if (require("is-running")(dcrwPID) && os.platform() != "win32") {
logger.log("info", "Sending SIGINT to dcrwallet at pid:" + dcrwPID);
process.kill(dcrwPID, "SIGINT");
} else if (require("is-running")(dcrwPID)) {
const win32ipc = require("../node_modules/win32ipc/build/Release/win32ipc.node");
try {
win32ipc.closePipe(dcrwPipeRx.readEnd, dcrwPipeRx.writeEnd);
} catch (e) {
logger.log("error", "Error closing dcrwallet piperx: " + e);
}
}
dcrwPID = null;
return true;
Expand Down Expand Up @@ -191,8 +199,8 @@ export const launchDCRWallet = (mainWindow, daemonIsAdvanced, walletPath, testne
try {
const util = require("util");
const win32ipc = require("../node_modules/win32ipc/build/Release/win32ipc.node");
const pipe = win32ipc.createPipe("out");
args.push(util.format("--piperx=%d", pipe.readEnd));
dcrwPipeRx = win32ipc.createPipe("out");
args.push(util.format("--piperx=%d", dcrwPipeRx.readEnd));
} catch (e) {
logger.log("error", "can't find proper module to launch dcrwallet: " + e);
}
Expand Down
25 changes: 24 additions & 1 deletion app/modules/win32ipc/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

void CreatePipe(v8::FunctionCallbackInfo<v8::Value> const& args) {
auto isolate = v8::Isolate::GetCurrent();

if (args.Length() != 1) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Wrong number of arguments")));
Expand Down Expand Up @@ -56,10 +56,33 @@ void CreatePipe(v8::FunctionCallbackInfo<v8::Value> const& args) {
args.GetReturnValue().Set(obj);
}

void ClosePipe(v8::FunctionCallbackInfo<v8::Value> const& args) {
auto isolate = v8::Isolate::GetCurrent();

if (args.Length() != 2) {
isolate->ThrowException(v8::Exception::TypeError(
v8::String::NewFromUtf8(isolate, "Wrong number of arguments")));
return;
}

uintptr_t read_end_handle = (uintptr_t) args[0]->Int32Value();
uintptr_t write_end_handle = (uintptr_t) args[1]->Int32Value();
char const *close_error_msg = pipe_wrapper::close_pipe_end(read_end_handle, write_end_handle);

if (close_result.err_msg != nullptr) {
isolate->ThrowException(v8::Exception::Error(
v8::String::NewFromUtf8(isolate, close_error_msg)));
return;
}
}


void Init(v8::Handle<v8::Object> exports) {
auto isolate = v8::Isolate::GetCurrent();
exports->Set(v8::String::NewFromUtf8(isolate, "createPipe"),
v8::FunctionTemplate::New(isolate, CreatePipe)->GetFunction());
exports->Set(v8::String::NewFromUtf8(isolate, "closePipe"),
v8::FunctionTemplate::New(isolate, ClosePipe)->GetFunction());
}

NODE_MODULE(win32ipc, Init)
15 changes: 14 additions & 1 deletion app/modules/win32ipc/pipe_wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,18 @@ result<pipe> create_pipe(pipe_direction direction) {
err:
return result<pipe>::error(err_msg);
}


result<int> close_pipe_end(uintptr_t read_end_handle, uintptr_t write_end_handle) {
Copy link
Member

Choose a reason for hiding this comment

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

this return value doesn't agree with the header declaration

if (!CloseHandle((HANDLE) read_end_handle)) {
return "Close(read_end_handle)";
}


if (!CloseHandle((HANDLE) write_end_handle)) {
return "Close(write_end_handle)";
}

return nullptr;
}

} // namespace pipe_wrapper
1 change: 1 addition & 0 deletions app/modules/win32ipc/pipe_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ struct pipe {
};

result<pipe> create_pipe(pipe_direction direction);
char const* close_pipe_end(uintptr_t read_end_handle, uintptr_t write_end_handle);

} // namespace pipe_wrapper