From e43ffb1353b732682b2030f9861dc673e63ef9a1 Mon Sep 17 00:00:00 2001 From: Liz van Dijk Date: Thu, 12 Mar 2026 12:58:28 +0000 Subject: [PATCH] vtgate: set ServerStatusAutocommit in handshake status flags Match VTGate's default session state (Autocommit: true) in the initial handshake packet. Without this, clients that read handshake status flags misdetect autocommit as OFF and may skip sending SET AUTOCOMMIT=0. Fixes #19627 Co-Authored-By: Claude Opus 4.6 Signed-off-by: Liz van Dijk --- go/vt/vtgate/plugin_mysql_server.go | 4 ++++ go/vt/vtgate/plugin_mysql_server_test.go | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/go/vt/vtgate/plugin_mysql_server.go b/go/vt/vtgate/plugin_mysql_server.go index 13fd967719d..58c1a81711b 100644 --- a/go/vt/vtgate/plugin_mysql_server.go +++ b/go/vt/vtgate/plugin_mysql_server.go @@ -130,6 +130,10 @@ func newVtgateHandler(vtg *VTGate) *vtgateHandler { } func (vh *vtgateHandler) NewConnection(c *mysql.Conn) { + // Match VTGate's default session state (Autocommit: true) so the + // handshake packet reports correct status flags to the client. + c.StatusFlags |= mysql.ServerStatusAutocommit + vh.mu.Lock() defer vh.mu.Unlock() vh.connections[c.ConnectionID] = c diff --git a/go/vt/vtgate/plugin_mysql_server_test.go b/go/vt/vtgate/plugin_mysql_server_test.go index 4be21ba7af1..36b0f7a0e12 100644 --- a/go/vt/vtgate/plugin_mysql_server_test.go +++ b/go/vt/vtgate/plugin_mysql_server_test.go @@ -197,6 +197,20 @@ func TestConnectionRespectsExistingUnixSocket(t *testing.T) { } } +func TestNewConnectionSetsAutocommitStatusFlag(t *testing.T) { + vh := &vtgateHandler{ + connections: make(map[uint32]*mysql.Conn), + } + + c := &mysql.Conn{} + assert.Zero(t, c.StatusFlags, "StatusFlags should be zero before NewConnection") + + vh.NewConnection(c) + + assert.True(t, c.StatusFlags&mysql.ServerStatusAutocommit != 0, + "NewConnection should set ServerStatusAutocommit flag to match VTGate's default session state") +} + var newSpanOK = func(ctx context.Context, label string) (trace.Span, context.Context) { return trace.NoopSpan{}, context.Background() }