-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
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. |
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' ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary change.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alignment is off here.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary whitespace change.
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
} | ||
} | ||
|
||
std::string GetProcessTitle() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be unused.
There was a problem hiding this comment.
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...
@bnoordhuis Thank you for reviewing it. I addressed your comments (and also did another pass through function names and such). Please take another look. |
I am looking to rework this quite a bit, to define an easier to use API. Please do not review it for now. |
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); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused, it seems?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target_ids
There was a problem hiding this comment.
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); | ||
} | ||
}; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny alignment.
There was a problem hiding this comment.
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_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off.
There was a problem hiding this comment.
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_); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off.
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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 <
.
There was a problem hiding this comment.
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); | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@bnoordhuis Thank you for the review. I uploaded updated commit, please take another look. |
@bnoordhuis I've updated the change, fixing the cpplint comment on the new test. |
I see a FreeBSD test failure that does not seem to be connected to this change. |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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. |
Landed as 42da740 |
@Fishrock123 this is another example of something that likely should not have gotten the |
@eugeneo should this be backported to v6 or is this an example of something that requires the latest version of inspector api? |
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. |
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>
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>
If this is backported it should be backported with #10657 |
Checklist
make -j8 test
(UNIX), orvcbuild test nosign
(Windows) passesAffected 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