You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by "raghav-reglobe (via GitHub)" <gi...@apache.org> on 2026/10/06 20:08:38 UTC

[PR] [fix](mysql) Read MySQL packets out of TLS records by packet length, not record length [doris]

raghav-reglobe opened a new pull request, #68748:
URL: https://github.com/apache/doris/pull/68748

   ### What problem does this PR solve?
   
   Issue Number: close #68747
   
   Related PR: #68745 touches the same file (it adds the compressed protocol and reads compressed frames through its own
   decrypted-stream reader); the two are independent and either can go first, the other rebases in a few lines.
   
   Problem Summary:
   
   On a TLS channel, `MysqlChannel.fetchOnePacket()` decided whether a MySQL packet continues in the next one by looking at the
   length of the last TLS record it had read. A statement longer than 16 MiB arrives as a 0xFFFFFF-byte packet followed by
   continuation packets; over TLS the reader stopped after the first, the next read took the continuation for a new command, the
   sequence check failed and the connection was closed (`ERROR 2013` on the client). The same statement over a plain socket worked.
   
   What this PR does:
   
   - The reader takes the plain application bytes through one path, `readPlaintext`: a plain socket read on a plain channel, the
     decrypted content of TLS records on an SSL one, with a record's surplus kept in `remainingBuffer` for the next call. Packet
     headers, sequence ids and the 0xFFFFFF continuation rule are then applied to that byte stream the same way on both kinds of
     channel. A packet may span many records and a record may carry several packets; neither boundary is visible above.
   - The TLS handshake keeps its own path (`fetchOneTlsRecord`), which hands whole records, header included, to the `SSLEngine`.
   - Nothing changes on the send side or in the handshake; the plain-socket read path is the same loop it was.
   
   ### Release note
   
   Fix: a TLS session to the FE lost its connection on any statement longer than 16 MiB (`ERROR 2013`); the FE now reads such
   statements over TLS as it does over a plain socket.
   
   ### Check List (For Author)
   
   - Test <!-- At least one of them must be included. -->
       - [x] Regression test <!-- the existing TLS suites, unchanged -->
       - [x] Unit Test — `MysqlChannelTlsPacketTest` (new): a 16 MiB + 100 KB statement, an exact 0xFFFFFF payload with its empty
         continuation, two continuations, several packets in one record, a packet cut across odd record boundaries (the header
         itself split), a continuation out of sequence refused, and the plain-socket case.
       - [x] Manual test (add detailed scripts or steps below) — an FE with `enable_ssl = true`: `mysql --ssl-mode=REQUIRED
         --max-allowed-packet=67108864` sending `SELECT length('<17,000,000 bytes>')` returns `17000000` (was `ERROR 2013`), a
         33.6 MB literal (two continuations) and a statement of exactly 0xFFFFFF bytes return their lengths, a 100K-row result
         pulled over TLS is byte-identical to the plain pull, the FE log has no `Bad packet sequence`.
       - [ ] No need to test or manual test. Explain why:
   
   - Behavior changed:
       - [x] No.
       - [ ] Yes. <!-- Explain the behavior change -->
   
   - Does this need documentation?
       - [x] No.
       - [ ] Yes. <!-- Add document PR link here. eg: https://github.com/apache/doris-website/pull/1214 -->
   
   ### Check List (For Reviewer who merge this PR)
   
   - [ ] Confirm the release note
   - [ ] Confirm test cases
   - [ ] Confirm document
   - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [fix](mysql) Read MySQL packets out of TLS records by packet length, not record length [doris]

Posted by "hello-stephen (via GitHub)" <gi...@apache.org>.
hello-stephen commented on PR #68748:
URL: https://github.com/apache/doris/pull/68748#issuecomment-6024522448

   
   Thank you for your contribution to Apache Doris.
   Don't know what should be done next? See [How to process your PR](https://doris.apache.org/community/how-to-contribute/review-and-ci).
   
   Please clearly describe your PR:
   1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
   2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
   3. What features were added. Why was this function added?
   4. Which code was refactored and why was this part of the code refactored?
   5. Which functions were optimized and what is the difference before and after the optimization?
       


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


Re: [PR] [fix](mysql) Read MySQL packets out of TLS records by packet length, not record length [doris]

Posted by "raghav-reglobe (via GitHub) via commits" <co...@doris.apache.org>.
raghav-reglobe commented on PR #68748:
URL: https://github.com/apache/doris/pull/68748#issuecomment-6582130777

   <!-- doris-repo-review:v1:begin -->
   ### Local pipeline review — ✅ PASS
   
   ```yaml
   schema: doris-repo-review/v1
   status: PASS
   pr: apache/doris#68748
   commit: 2f1ac3901596d339212090b2ceec34d94cb9efe2
   base: 6fafa3195ee4e90ddfb4d2b9c8e424e693d60512
   reviewed_at: 2026-11-02T21:46+05:30
   reviewer: raghav-reglobe
   model: claude-fable-5-1
   effort: xhigh
   findings: {blocker: 0, major: 0, minor: 4, nit: 3}
   rounds: 1
   converged: true
   ```
   
   **Notes for maintainers**
   
   - `fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlChannel.java:432` — Minor: when the decrypted record is the peer's `close_notify` (0 bytes produced, engine inbound done) `readPlaintext` treats it as an empty record and reads the next TLS record; a client that sends `close_notify` without `COM_QUIT` and keeps TCP open (OpenSSL's second `SSL_shutdown`, Python `ssl.unwrap()`) then holds an XNIO task thread until `wait_timeout`. Null-safe fix: return after `decryptData` when `sslEngine.isInboundDone()`, plus a test.
   - `fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlChannel.java:435` — Minor, pre-existing on the base but now documented as supported: a complete second command parked in `remainingBuffer` is only read on the next readable event, which a request/response client never sends (node mysql2 coalesces `COM_STMT_CLOSE` + `COM_QUERY` into one TLS record); a drain loop in `ReadListener` over `hasBufferedInput()` closes it (not `wakeupReads()`, which double-dispatches).
   - Not verified locally: no build, unit or regression run; evidence is the diff, XNIO 3.8.14 and JDK 17 sources, and the named client libraries' write paths. No regression suite sends a 0xFFFFFF-byte packet over TLS, so the continuation rule rests on the unit test's identity cipher.
   
   <sub>Reviewed locally with the `doris-repo-review` pipeline. Repository policy may accept this receipt for the matching commit; it is not a human Apache approval.</sub>
   <!-- doris-repo-review:v1:end -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org