Repository navigation
Description
Title: mysql proxy: ignoring out-of-sync packet message occur when login
Description:
When I login mysql server, envoy raises log "ignoring out-of-sync packet message".
Repro steps:
- MySQL server version: 5.5.59 Docker image
- Envoy version: build from main branch
- mysql setup
$ docker pull docker pull cytopia/mysql-5.5
$ docker docker run -i \
-p 127.0.0.1:9999:3306 \
-v ~tmp/mysql-log:/var/log/mysql \
-e MYSQL_ROOT_PASSWORD={my-secret-pw} \
-e MYSQL_GENERAL_LOG=1 \
-t cytopia/mysql-5.5- envoy setup
$ bazel build //source/exe:envoy-static
$ ${path of envoy-static} -c mysql-proxy.yaml --concurrency 1 - mysql client
$ mysql -uroot -P 9001 -p{my-secret-pw} --protocol tcp -h 127.0.0.1 --connect-timeout=100 --skip-sslConfig:
- mysql-proxy.yaml
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 9001
filter_chains:
- filters:
- name: envoy.filters.network.mysql_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.mysql_proxy.v3.MySQLProxy
stat_prefix: mysql
- name: envoy.filters.network.tcp_proxy
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
stat_prefix: tcp
cluster: local_service
clusters:
- name: local_service
connect_timeout: 0.25s
type: strict_dns
lb_policy: LEAST_REQUEST
load_assignment:
cluster_name: local_service
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: 127.0.0.1
port_value: 9999
admin:
access_log_path: "/dev/null"
address:
socket_address:
address: 0.0.0.0
port_value: 8081Logs:
[2021-02-07 16:08:40.774][66952][info][main] [source/server/server.cc:652] runtime: layers:
- name: base
static_layer:
{}
- name: admin
admin_layer:
{}
[2021-02-07 16:08:40.775][66952][info][config] [source/server/configuration_impl.cc:125] loading tracing configuration
[2021-02-07 16:08:40.775][66952][info][config] [source/server/configuration_impl.cc:85] loading 0 static secret(s)
[2021-02-07 16:08:40.775][66952][info][config] [source/server/configuration_impl.cc:91] loading 1 cluster(s)
[2021-02-07 16:08:40.783][66952][info][config] [source/server/configuration_impl.cc:95] loading 1 listener(s)
[2021-02-07 16:08:40.793][66952][info][config] [source/server/configuration_impl.cc:107] loading stats configuration
[2021-02-07 16:08:40.793][66952][info][runtime] [source/common/runtime/runtime_impl.cc:425] RTDS has finished initialization
[2021-02-07 16:08:40.793][66952][info][upstream] [source/common/upstream/cluster_manager_impl.cc:191] cm init: all clusters initialized
[2021-02-07 16:08:40.793][66952][warning][main] [source/server/server.cc:627] there is no configured limit to the number of allowed active connections. Set a limit via the runtime key overload.global_downstream_max_connections
[2021-02-07 16:08:40.794][66952][info][main] [source/server/server.cc:730] all clusters initialized. initializing init manager
[2021-02-07 16:08:40.794][66952][info][config] [source/server/listener_manager_impl.cc:884] all dependencies initialized. starting workers
[2021-02-07 16:08:40.794][66952][info][main] [source/server/server.cc:749] starting main dispatch loop
[2021-02-07 16:08:54.513][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:08:54.514][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:08:54.514][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:08:54.514][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:09:12.608][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:09:12.608][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:09:12.609][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:09:12.609][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:09:12.609][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
[2021-02-07 16:09:12.609][66959][info][filter] [source/extensions/filters/network/mysql_proxy/mysql_decoder.cc:154] mysql_proxy: ignoring out-of-sync packet
I have debugged at vscode, it seems that the command phase of MySQL decoder is not well addressed. The decoder will execute state machine when a packet is coming, it assumes the ping-pong mode. It works well in connection phase, but in command phase, every packet of client request will start at sequence id 0, but the server response is not always only one packet, it might contain multiply packets with sequence id continuously ref. This will cause serveral issues:
- The
resultofquerywill decode byCommand.decodewhich should only decodequery. - Assume the server response contains packets with sequence id [2, 3, 4], the packet 2 will decode by
CommandResp, then theExpectedSeqwill be set to 0. When packet 3 is coming,expected seq 1 != actual seq 3then log "ignoring out-of-sync packet".
// Process Command
case MySQLSession::State::Req: {
Command command{};
command.decode(message, seq, len);
callbacks_.onCommand(command);
session_.setState(MySQLSession::State::ReqResp);
break;
}
// Process Command Response
case MySQLSession::State::ReqResp: {
CommandResponse command_resp{};
command_resp.decode(message, seq, len);
callbacks_.onCommandResponse(command_resp);
session_.setState(MySQLSession::State::Req);
session_.setExpectedSeq(MYSQL_REQUEST_PKT_NUM);
break;
}If the command phase of MySQL communication can not be well addressed, the feature pointed out at https://www.envoyproxy.io/docs/envoy/latest/configuration/listeners/network_filters/mysql_proxy_filter#dynamic-metadata will not really work.
Activity
qinggniq commentedon Feb 7, 2021
ping @rshriram @venilnoronha @mattklein123 as code owners.
qinggniq commentedon Feb 8, 2021
Closed due to misunderstand the codec behavior of command phase, it will ignore all redundant command responses and ensure parse
command, so thedynamic-metadatawill still work.