From 62b8080699371b0bcd83e2c3ddda265d22d0eb40 Mon Sep 17 00:00:00 2001 From: Kartik Pattaswamy <62078498+kpattaswamy@users.noreply.github.com> Date: Mon, 6 Nov 2023 08:39:10 -0800 Subject: [PATCH] Update buffer position when returning kIgnored (#1760) Summary: This PR removes the frame's contents from the buffer in the case we return `kIgnored` when the frame is a type (opcode) we do not parse. When running the BPF test we noticed that the program would stall when the parser encountered a frame with an opcode it does not support. This was due to to the parser returning `kIgnored` to `ParseFramesLoop` and it not moving the buffer forward before calling `ParseFrame` again. This change will update the buffer position before returning `kIgnored` to `ParseFramesLoop` so that the remaining frames in the buffer can be parsed. Related issues: https://github.com/pixie-io/pixie/issues/640 Type of change: /kind bug Test Plan: Modified the existing test checking for the unsupported opcode type. Signed-off-by: Kartik Pattaswamy --- .../socket_tracer/protocols/mongodb/parse.cc | 7 ++++--- .../socket_tracer/protocols/mongodb/parse_test.cc | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse.cc b/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse.cc index 3c2ca0911dd..56f58a8754d 100644 --- a/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse.cc +++ b/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse.cc @@ -64,9 +64,10 @@ ParseState ParseFrame(message_type_t type, std::string_view* buf, Frame* frame, return ParseState::kInvalid; } - // Parser will ignore Op Codes that have been deprecated/removed from version 5.0 onwards. - if (!(frame_type == Type::kOPMsg || frame_type == Type::kOPCompressed || - frame_type == Type::kReserved)) { + // Parser will ignore Op Codes that have been deprecated/removed from version 5.0 onwards as well + // as kOPCompressed and kReserved which are not supported by the parser yet. + if (frame_type != Type::kOPMsg) { + buf->remove_prefix(frame->length); return ParseState::kIgnored; } diff --git a/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse_test.cc b/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse_test.cc index ba587af622c..b6c89f0455d 100644 --- a/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse_test.cc +++ b/src/stirling/source_connectors/socket_tracer/protocols/mongodb/parse_test.cc @@ -391,6 +391,7 @@ TEST_F(MongoDBParserTest, ParseFrameWhenUnsupportedType) { ParseState state = ParseFrame(message_type_t::kRequest, &frame_view, &frame, &state_order); EXPECT_EQ(state, ParseState::kIgnored); + EXPECT_EQ(frame_view.length(), 0); } TEST_F(MongoDBParserTest, ParseFrameInvalidFlagBits) {