Skip to content

mysql_filter: add handling for partial messages#6885

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
venilnoronha:mysql-buffer-fix
May 23, 2019
Merged

mysql_filter: add handling for partial messages#6885
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
venilnoronha:mysql-buffer-fix

Conversation

@venilnoronha
Copy link
Member

Description: This adds logic to handle partially buffered protocol messages in the MySQL filter.
Risk Level: Med
Testing: Added a new test
Docs Changes: N/A
Release Notes: N/A
Fixes #6696

This adds logic to handle partially buffered protocol messages in the
MySQL filter.

Signed-off-by: Venil Noronha <veniln@vmware.com>
}

void MySQLFilter::doDecode(Buffer::Instance& buffer) {
// Safety measure just to make sure that if we have a decoding error we keep going and lose stats.
Copy link
Member

Choose a reason for hiding this comment

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

don't think this comment applies anymore?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it'd be valid as long as there's the sniffing_ variable.

@stale
Copy link

stale bot commented May 18, 2019

This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale stalebot believes this issue/PR has not been touched recently label May 18, 2019
Copy link
Member

@rshriram rshriram left a comment

Choose a reason for hiding this comment

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

Can you add a test for the sniffing code as well?

@stale stale bot removed the stale stalebot believes this issue/PR has not been touched recently label May 18, 2019
Signed-off-by: Venil Noronha <veniln@vmware.com>
if (!sniffing_) {
buffer.drain(buffer.length());
return;
if (sniffing_) {
Copy link
Member

Choose a reason for hiding this comment

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

could you remind me how this sniffing works? the github diff is not showing the entire thing.. I remember this was a boolean that indicated whether we had a decoding error or not and if there was an error, it would simply forward all data as is. But you seem to have flipped the condition.. why?

Copy link
Member Author

Choose a reason for hiding this comment

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

If there was a decoding error, we used to empty the buffer. That isn't correct. We need to retain the information in the buffer as that's what is being passed to the next filter (and eventually to MySQL).

In this new logic, I'm not modifying the original buffer instance at all. I'm only copying its contents to a new read_buffer_/write_buffer_ instance if the sniffing_ flag is set to true. I've flipped the logic to just reorganize the code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Now, if there's a decoding error, nothing will be copied over to the read/write buffers; however, the original contents of the message will still be forwarded to the next filter hoping that MySQL will be able to handle it correctly.

rshriram
rshriram previously approved these changes May 22, 2019
Copy link
Member

@rshriram rshriram left a comment

Choose a reason for hiding this comment

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

LGTM

thanks for the fix handling partial messages

@venilnoronha
Copy link
Member Author

@mattklein123 this is ready for a final pass.

Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Quickly skimmed and just caught one thing. Also please go through and make sure all the MySQL code has coverage. We are running up against the limit. Thank you!

/wait


protected:
virtual int parseMessage(Buffer::Instance& data, uint64_t& offset, int len) PURE;
virtual int parseMessage(Buffer::Instance& data, int len) PURE;
Copy link
Member

Choose a reason for hiding this comment

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

Not in this change but can you update int to a proper unsigned type? Same above for decode and other places it applies in this PR? Thank you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed in 9968c6a.

This updates variable types from int to uint32_t for the length field
and uint8_t for the sequence ID field in the MySQL proxy filter.

Signed-off-by: Venil Noronha <veniln@vmware.com>
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

@mattklein123 mattklein123 self-assigned this May 23, 2019
@mattklein123 mattklein123 merged commit cfff658 into envoyproxy:master May 23, 2019
mpuncel added a commit to mpuncel/envoy that referenced this pull request May 23, 2019
* master:
  test: Add coverage for IsolatedStoreImpl::find* (envoyproxy#7043)
  server: add ProcessContext (envoyproxy#7018)
  config: Implement both versions of onConfigUpdate() everywhere (envoyproxy#6879)
  gzip: add test for various compression strategy and level (envoyproxy#7055)
  Fix typo in comment for rds.RouteConfiguration.validate_clusters (envoyproxy#7056)
  mysql_filter: add handling for partial messages (envoyproxy#6885)
  migrate from v2alpha to v2 (envoyproxy#7044)
  tests: fix tsan test flake (envoyproxy#7052)
  upstream: fix HostUtility::healthFlagsToString (envoyproxy#7051)
  tech debt: eliminate absl::make_unique (envoyproxy#7034)
  router: add a route name field in route.Route list (envoyproxy#6776)
  ext_authz: configurable HTTP status code for network errors. (envoyproxy#6669)
  stats: remove const-cast for symbol-table in edcs_filter_test.cc (envoyproxy#7045)
  build: bump libevent to 3b1864b. (envoyproxy#7012)
  stats: improve test-coverage for a few stats-related functions. (envoyproxy#7038)
  docs: fix csrf filter source origin note (envoyproxy#7041)
  Fix common typo: grcp -> grpc (envoyproxy#7040)
  snapshot (envoyproxy#7036)

Signed-off-by: Michael Puncel <mpuncel@squareup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mysql filter fails to parse a partial mysql message

4 participants