Permalink
Browse files

inspector: handle socket close before close frame

This change handles clients that respond to close request with a TCP
close instead of close response.

PR-URL: #12937
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information...
Eugene Ostroukhov
Eugene Ostroukhov committed May 9, 2017
1 parent 642bd4d commit 7c3a23b9c121b816c551d2560df9ee2bc63f2555
Showing with 35 additions and 1 deletion.
  1. +4 −0 src/inspector_socket.cc
  2. +31 −1 test/cctest/test_inspector_socket.cc
View
@@ -335,6 +335,10 @@ static void websockets_data_cb(uv_stream_t* stream, ssize_t nread,
if (!inspector->shutting_down && inspector->ws_state->read_cb) {
inspector->ws_state->read_cb(stream, nread, nullptr);
}
if (inspector->ws_state->close_sent &&
!inspector->ws_state->received_close) {
shutdown_complete(inspector); // invoke callback
}
} else {
#if DUMP_READS
printf("%s read %ld bytes\n", __FUNCTION__, nread);
@@ -35,6 +35,8 @@ static std::string last_path; // NOLINT(runtime/string)
static void (*handshake_delegate)(enum inspector_handshake_event state,
const std::string& path,
bool* should_continue);
static const char SERVER_CLOSE_FRAME[] = {'\x88', '\x00'};
struct read_expects {
const char* expected;
@@ -879,7 +881,6 @@ TEST_F(InspectorSocketTest, Send1Mb) {
// 3. Close
const char CLIENT_CLOSE_FRAME[] = {'\x88', '\x80', '\x2D',
'\x0E', '\x1E', '\xFA'};
const char SERVER_CLOSE_FRAME[] = {'\x88', '\x00'};
do_write(CLIENT_CLOSE_FRAME, sizeof(CLIENT_CLOSE_FRAME));
expect_on_client(SERVER_CLOSE_FRAME, sizeof(SERVER_CLOSE_FRAME));
GTEST_ASSERT_EQ(0, uv_is_active(
@@ -906,4 +907,33 @@ TEST_F(InspectorSocketTest, ErrorCleansUpTheSocket) {
EXPECT_EQ(UV_EPROTO, err);
}
static void ServerClosedByClient_cb(InspectorSocket* socket, int code) {
*static_cast<bool*>(socket->data) = true;
}
TEST_F(InspectorSocketTest, NoCloseResponseFromClinet) {
ASSERT_TRUE(connected);
ASSERT_FALSE(inspector_ready);
do_write(const_cast<char*>(HANDSHAKE_REQ), sizeof(HANDSHAKE_REQ) - 1);
SPIN_WHILE(!inspector_ready);
expect_handshake();
// 2. Brief exchange
const char SERVER_MESSAGE[] = "abcd";
const char CLIENT_FRAME[] = {'\x81', '\x04', 'a', 'b', 'c', 'd'};
inspector_write(&inspector, SERVER_MESSAGE, sizeof(SERVER_MESSAGE) - 1);
expect_on_client(CLIENT_FRAME, sizeof(CLIENT_FRAME));
bool closed = false;
inspector.data = &closed;
inspector_close(&inspector, ServerClosedByClient_cb);
expect_on_client(SERVER_CLOSE_FRAME, sizeof(SERVER_CLOSE_FRAME));
uv_close(reinterpret_cast<uv_handle_t*>(&client_socket), nullptr);
SPIN_WHILE(!closed);
inspector.data = nullptr;
GTEST_ASSERT_EQ(0, uv_is_active(
reinterpret_cast<uv_handle_t*>(&client_socket)));
}
} // anonymous namespace

0 comments on commit 7c3a23b

Please sign in to comment.