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

inspector: split HTTP/WS server from the inspector #9630

Merged
merged 0 commits into from
Dec 6, 2016
Merged

inspector: split HTTP/WS server from the inspector #9630

merged 0 commits into from
Dec 6, 2016

Conversation

eugeneo
Copy link
Contributor

@eugeneo eugeneo commented Nov 16, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

inspector: HTTP server code was reworked and moved to a new file. No impact if the inspector is not started.

Description of change

Both our team experiments and some embedder request indicate a potential
in implementing alternative transport for inspector - e.g. IPC pipes or
custom embedder APIs. This change moves all HTTP specific code into a
separate class and is a first attempt at defining a boundary between the
inspector agent and transport. This API will be refined as new
transports are implemented.
Note that even without considering alternative transports, this change
enables better testing of the HTTP server (Valgrind it possible to identify
and fix some existing memory leaks).

CC: @ofrobots

@nodejs-github-bot nodejs-github-bot added build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++. labels Nov 16, 2016
@bnoordhuis
Copy link
Member

Related test failures on the OS X buildbot: https://ci.nodejs.org/job/node-test-commit-osx/6038/nodes=osx1010/console - some inspector cctests are failing.

@eugeneo
Copy link
Contributor Author

eugeneo commented Nov 17, 2016

I fixed the issues CI identified. New CI run (https://ci.nodejs.org/job/node-test-pull-request/4863/) seems to pass on all platforms, except ARM. Failures there seem to have to do with infrastructure failures unrelated to this PR.

@@ -865,10 +867,11 @@
{
'target_name': 'cctest',
'type': 'executable',
'dependencies': [ 'deps/gtest/gtest.gyp:gtest' ],
'dependencies': ['deps/gtest/gtest.gyp:gtest' ],
Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

const std::string& script_name, bool wait);
InspectorSession* StartSession(const std::string& id) override;
void MessageReceived(InspectorSession* session,
const std::string& message) override;
Copy link
Member

Choose a reason for hiding this comment

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

Alignment is off here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

void EndSession(InspectorSession* session) override;
const std::vector<std::string> GetTargetIds() override;
const std::string GetTargetTitle(const std::string& id) override;
const std::string GetTargetUrl(const std::string& id) override;
Copy link
Member

Choose a reason for hiding this comment

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

Returning const values (not references) is kind of odd. Doesn't g++ complain about that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It did not complain (neither did clang/Mac), I removed the const none the less.

bool AgentImpl::IsStarted() {
return !!platform_;
}

void AgentImpl::WaitForDisconnect() {
shutting_down_ = true;
Write(0, StringView());
Copy link
Member

Choose a reason for hiding this comment

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

Why is this necessary? An explaining comment would be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a temporary "command" to stop accepting new connections. In next pull request there will be a better API with meaningful requests as opposed to magical strings...

}
if (err != 0) {
InspectorAgentDelegate delegate(this, script_path, script_name_, wait_);
delegate_ = &delegate;
Copy link
Member

Choose a reason for hiding this comment

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

You don't seem to reset delegate_ to nullptr anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

uv_loop_close(&child_loop_);
uv_sem_post(&start_sem_);
return;
}
PrintDebuggerReadyMessage(port_, id_);
server_ = &server;
Copy link
Member

Choose a reason for hiding this comment

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

Ditto for server_, it looks like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

#if !HAVE_INSPECTOR
#error("This header can only be used when inspector is enabled")
#endif


Copy link
Member

Choose a reason for hiding this comment

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

Unnecessary whitespace change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -37,6 +40,10 @@ class Agent {
bool IsConnected();
void WaitForDisconnect();

void PostMessage(char* data, size_t len);
void StartSession();
void EndSession();
Copy link
Member

Choose a reason for hiding this comment

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

These methods don't seem to be used or defined anywhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, at some points was considering a slightly different API.

fprintf(stderr,
"Debugger listening on port %d.\n"
"Warning: This is an experimental feature and could change at any time.\n",
port);
Copy link
Member

Choose a reason for hiding this comment

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

Can you line up the arguments?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
}

std::string GetProcessTitle() {
Copy link
Member

Choose a reason for hiding this comment

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

Seems to be unused.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this ultimately remained in inspector_agent.cc...

@eugeneo
Copy link
Contributor Author

eugeneo commented Nov 17, 2016

@bnoordhuis Thank you for reviewing it. I addressed your comments (and also did another pass through function names and such). Please take another look.

@eugeneo
Copy link
Contributor Author

eugeneo commented Nov 22, 2016

I am looking to rework this quite a bit, to define an easier to use API. Please do not review it for now.

@eugeneo
Copy link
Contributor Author

eugeneo commented Nov 22, 2016

PR had been reworked, please review. I replaced the Session object with an integer session_id, it simplified the API.

auto found = std::find(callbacks_.begin(), callbacks_.end(), callback);
if (found == callbacks_.end()) {
callbacks_.push_back(callback);
}
Copy link
Member

Choose a reason for hiding this comment

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

Not at all critical but doesn't it make more sense to use a std::set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const uv_buf_t* buf);
static void ReleaseMemory(InspectorSocket* socket, int code) {
delete SocketSession::From(socket);
}
Copy link
Member

Choose a reason for hiding this comment

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

Unused, it seems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, thanks.

}

bool InspectorSocketServer::TargetExists(const std::string& id) {
const std::vector<std::string>& targetIds = delegate_->GetTargetIds();
Copy link
Member

Choose a reason for hiding this comment

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

target_ids

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

}
EXPECT_EQ(0, err);
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Can you share this code with test_inspector_socket.cc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That test is due for a more comprehensive cleanup so I will do it then (this will require adding new files, etc).

}

bool StartSession(int session_id,
const std::string& target_id) override {
Copy link
Member

Choose a reason for hiding this comment

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

Funny alignment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

uv_ip4_addr(host.c_str(), PORT, &addr);
int err = uv_tcp_connect(&connect_, &socket_,
reinterpret_cast<const sockaddr*>(&addr),
Connected_);
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

uv_ip4_addr(host.c_str(), PORT, &addr);
int err = uv_tcp_connect(&connect_, &socket_,
reinterpret_cast<const sockaddr*>(&addr),
ConnectionMustFail_);
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

wrapper->eof_ = true;
} else {
wrapper->contents_.insert(wrapper->contents_.end(), buf->base,
buf->base + read);
Copy link
Member

Choose a reason for hiding this comment

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

Indentation is off.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.


class ServerHolder {
public:
template<typename Delegate>
Copy link
Member

Choose a reason for hiding this comment

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

Teeny tiny nit: we usually put a space before the <.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

socket1.TestHttpRequest("/json/list", "[ ]");
socket1.Close();
uv_run(&loop, UV_RUN_DEFAULT);
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you fix the long lines in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@eugeneo
Copy link
Contributor Author

eugeneo commented Nov 28, 2016

@bnoordhuis Thank you for the review. I uploaded updated commit, please take another look.

@eugeneo
Copy link
Contributor Author

eugeneo commented Dec 2, 2016

@bnoordhuis I've updated the change, fixing the cpplint comment on the new test.

@eugeneo
Copy link
Contributor Author

eugeneo commented Dec 2, 2016

I see a FreeBSD test failure that does not seem to be connected to this change.

Copy link
Member

@bnoordhuis bnoordhuis left a comment

Choose a reason for hiding this comment

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

LGTM with a suggestion.


// static
void InspectorSocketServer::ServerClosedCallback(uv_handle_t* server) {
InspectorSocketServer* sserver = InspectorSocketServer::From(server);
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion: s/sserver/socket_server/ - the difference between server and sserver is very subtle.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

#include <sstream>

using InspectorSocketServer = node::inspector::InspectorSocketServer;
using SocketServerDelegate = node::inspector::SocketServerDelegate;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the linter complaining about a using directive outside a namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved the directives inside the namespace. Linter was fine - don't know if it is because of its settings.

@eugeneo
Copy link
Contributor Author

eugeneo commented Dec 6, 2016

Looks like https://ci.nodejs.org/job/node-test-pull-request/5271/ is all green but some glitch is preventing thew results to be reported back to GitHuib.

@eugeneo eugeneo closed this Dec 6, 2016
@eugeneo eugeneo merged commit 42da740 into nodejs:master Dec 6, 2016
@eugeneo eugeneo deleted the socket_server branch December 6, 2016 22:50
@eugeneo
Copy link
Contributor Author

eugeneo commented Dec 6, 2016

Landed as 42da740

@MylesBorins
Copy link
Contributor

@Fishrock123 this is another example of something that likely should not have gotten the dont-land label

@MylesBorins
Copy link
Contributor

@eugeneo should this be backported to v6 or is this an example of something that requires the latest version of inspector api?

@eugeneo
Copy link
Contributor Author

eugeneo commented Dec 21, 2016

This is a refactoring and does not require a new V8 inspector. I am not sure if it is needed for v6 (I'm not familiar with the policies) as main goal is to enable development of new features.

evanlucas pushed a commit that referenced this pull request Jan 3, 2017
Both our team experiments and some embedder request indicate a potential
in implementing alternative transport for inspector - e.g. IPC pipes or
custom embedder APIs. This change moves all HTTP specific code into a
separate class and is a first attempt at defining a boundary between the
inspector agent and transport. This API will be refined as new
transports are implemented.
Note that even without considering alternative transports, this change
enables better testing of the HTTP server (Valgrind made it possible to
identify and fix some existing memory leaks).

PR-URL: #9630
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
evanlucas pushed a commit that referenced this pull request Jan 4, 2017
Both our team experiments and some embedder request indicate a potential
in implementing alternative transport for inspector - e.g. IPC pipes or
custom embedder APIs. This change moves all HTTP specific code into a
separate class and is a first attempt at defining a boundary between the
inspector agent and transport. This API will be refined as new
transports are implemented.
Note that even without considering alternative transports, this change
enables better testing of the HTTP server (Valgrind made it possible to
identify and fix some existing memory leaks).

PR-URL: #9630
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@gibfahn
Copy link
Member

gibfahn commented Mar 11, 2017

If this is backported it should be backported with #10657

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues and PRs related to build files or the CI. c++ Issues and PRs that require attention from people who are familiar with C++.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants