Skip to content

Commit 87026c0

Browse files
authored
Merge pull request #5245 from sysown/v3.0-issue5244
Permanent FF sessions + check_data_flow docs
2 parents 689bece + ec1247f commit 87026c0

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

lib/mysql_data_stream.cpp

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,12 +449,41 @@ void MySQL_Data_Stream::shut_hard() {
449449
}
450450
}
451451

452+
/**
453+
* @brief Checks data flow conditions and handles exceptional cases
454+
*
455+
* This function performs critical checks on the data flow state of a MySQL data stream connection.
456+
* It handles two main scenarios:
457+
* 1. Data present in both input and output queues simultaneously (bidirectional data)
458+
* 2. Backend connection establishment completion
459+
*
460+
* @note For permanent fast-forward sessions (SESSION_FORWARD_TYPE_PERMANENT), bidirectional data
461+
* generates a warning but continues operation. All other session types treat this as a fatal error.
462+
*
463+
* @warning In non-fast-forward sessions, bidirectional data will trigger:
464+
* - Error logging
465+
* - Soft shutdown of the connection
466+
* - Core dump generation for debugging
467+
*
468+
* For backend connections (MYDS_BACKEND) during establishment:
469+
* - Checks socket error status after a POLLOUT event
470+
* - On success: Associates socket fd with MySQL_Connection
471+
* - On error: Performs soft shutdown and logs perror()
472+
*
473+
* @see generate_coredump()
474+
* @see shut_soft()
475+
*/
452476
void MySQL_Data_Stream::check_data_flow() {
453477
if ( (PSarrayIN->len || queue_data(queueIN) ) && ( PSarrayOUT->len || queue_data(queueOUT) ) ){
454-
// there is data at both sides of the data stream: this is considered a fatal error
455-
proxy_error("Session=%p, DataStream=%p -- Data at both ends of a MySQL data stream: IN <%d bytes %d packets> , OUT <%d bytes %d packets>\n", sess, this, PSarrayIN->len , queue_data(queueIN) , PSarrayOUT->len , queue_data(queueOUT));
456-
shut_soft();
457-
generate_coredump();
478+
if (sess && sess->status == FAST_FORWARD && sess->session_fast_forward == SESSION_FORWARD_TYPE_PERMANENT) {
479+
// Permanent fast-forward sessions: log warning but continue
480+
proxy_warning("Session=%p, DataStream=%p -- Data at both ends of a MySQL data stream: IN <%d bytes %d packets> , OUT <%d bytes %d packets>\n", sess, this, queue_data(queueIN), PSarrayIN->len, queue_data(queueOUT), PSarrayOUT->len);
481+
} else {
482+
// All other sessions: treat as fatal error
483+
proxy_error("Session=%p, DataStream=%p -- Data at both ends of a MySQL data stream: IN <%d bytes %d packets> , OUT <%d bytes %d packets>\n", sess, this, queue_data(queueIN), PSarrayIN->len, queue_data(queueOUT), PSarrayOUT->len);
484+
shut_soft();
485+
generate_coredump();
486+
}
458487
}
459488
if ((myds_type==MYDS_BACKEND) && myconn && (myconn->fd==0) && (revents & POLLOUT)) {
460489
int rc;

0 commit comments

Comments
 (0)