[MDEV-21252] ER_HOST_IS_BLOCKED returns packet sequence 1 instead of 0 Created: 2019-12-09  Updated: 2022-01-12  Resolved: 2022-01-12

Status: Closed
Project: MariaDB Server
Component/s: Protocol, Server
Affects Version/s: 10.2, 10.3, 10.4
Fix Version/s: 10.2.42, 10.3.33, 10.4.23, 10.5.14, 10.6.6

Type: Bug Priority: Major
Reporter: Kosh Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 1
Labels: None
Environment:

Docker for repeatability and testing


Attachments: Zip Archive mariadb.pcap.zip    
Issue Links:
Problem/Incident
is caused by MDEV-19893 Do not send error packets with seqno= 0 Closed

 Description   

I discovered this while trying to debug the go client library.
https://github.com/go-sql-driver/mysql/issues/1038

I wrote some scripts to repeat the issue: https://github.com/koshatul/go-mysql-sync-issue

It only affected MariaDB 10.2+ where the 4th byte of the packet that is sequence is returning 1 instead of 0 when the host is blocked.

Example:
Sending 100 broken connections first to trigger the ER_HOST_IS_BLOCKED

10.0 and 10.1:

01101000 00000000 00000000 00000000

10.2, 10.3, 10.4:

01101000 00000000 00000000 00000001



 Comments   
Comment by Inada Naoki [ 2021-03-06 ]

Similar issue is reported to PyMySQL.
https://github.com/PyMySQL/PyMySQL/issues/971

In this issue, "1130 host not allowed" error sent wrong sequence number.

Please fix this issue ASAP. Otherwise, many users will report the issue to mysql drivers and drivers maintainers need to investigate the issues.

Comment by Kosh [ 2021-04-11 ]

I gathered the packet captures, i'll add them here to see if they help.
mariadb.pcap.zip

MariaDB 10.1:

No.     Time           Source                Destination           Protocol Length Info
      4 0.000155       172.17.0.2            172.17.0.1            MySQL    174    Server Greeting Error 1129
 
Frame 4: 174 bytes on wire (1392 bits), 174 bytes captured (1392 bits)
Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: 02:42:15:9f:91:76 (02:42:15:9f:91:76)
Internet Protocol Version 4, Src: 172.17.0.2, Dst: 172.17.0.1
Transmission Control Protocol, Src Port: 3306, Dst Port: 55812, Seq: 1, Ack: 1, Len: 108
MySQL Protocol
    Packet Length: 104
    Packet Number: 0
    Error Code: 1129
    Error message: Host '172.17.0.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
 
0000  02 42 15 9f 91 76 02 42 ac 11 00 02 08 00 45 08   .B...v.B......E.
0010  00 a0 05 c9 40 00 40 06 dc 61 ac 11 00 02 ac 11   ....@.@..a......
0020  00 01 0c ea da 04 10 f4 2e 63 96 4d aa 0e 80 18   .........c.M....
0030  01 fe 58 b8 00 00 01 01 08 0a 30 31 70 95 13 a7   ..X.......01p...
0040  d6 4f 68 00 00 00 ff 69 04 48 6f 73 74 20 27 31   .Oh....i.Host '1
0050  37 32 2e 31 37 2e 30 2e 31 27 20 69 73 20 62 6c   72.17.0.1' is bl
0060  6f 63 6b 65 64 20 62 65 63 61 75 73 65 20 6f 66   ocked because of
0070  20 6d 61 6e 79 20 63 6f 6e 6e 65 63 74 69 6f 6e    many connection
0080  20 65 72 72 6f 72 73 3b 20 75 6e 62 6c 6f 63 6b    errors; unblock
0090  20 77 69 74 68 20 27 6d 79 73 71 6c 61 64 6d 69    with 'mysqladmi
00a0  6e 20 66 6c 75 73 68 2d 68 6f 73 74 73 27         n flush-hosts'

MariaDB 10.4:

No.     Time           Source                Destination           Protocol Length Info
      4 0.000544       172.17.0.2            172.17.0.1            MySQL    174    Response Error 1129
 
Frame 4: 174 bytes on wire (1392 bits), 174 bytes captured (1392 bits)
Ethernet II, Src: 02:42:ac:11:00:02 (02:42:ac:11:00:02), Dst: 02:42:15:9f:91:76 (02:42:15:9f:91:76)
Internet Protocol Version 4, Src: 172.17.0.2, Dst: 172.17.0.1
Transmission Control Protocol, Src Port: 3306, Dst Port: 55324, Seq: 1, Ack: 1, Len: 108
MySQL Protocol
    Packet Length: 104
    Packet Number: 1
    Response Code: ERR Packet (0xff)
    Error Code: 1129
    Error message: Host '172.17.0.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
 
0000  02 42 15 9f 91 76 02 42 ac 11 00 02 08 00 45 08   .B...v.B......E.
0010  00 a0 ba 05 40 00 40 06 28 25 ac 11 00 02 ac 11   ....@.@.(%......
0020  00 01 0c ea d8 1c a2 b3 30 3d 5c 3f e4 6d 80 18   ........0=\?.m..
0030  01 fe 58 b8 00 00 01 01 08 0a 30 2c 43 33 13 a2   ..X.......0,C3..
0040  a8 ed 68 00 00 01 ff 69 04 48 6f 73 74 20 27 31   ..h....i.Host '1
0050  37 32 2e 31 37 2e 30 2e 31 27 20 69 73 20 62 6c   72.17.0.1' is bl
0060  6f 63 6b 65 64 20 62 65 63 61 75 73 65 20 6f 66   ocked because of
0070  20 6d 61 6e 79 20 63 6f 6e 6e 65 63 74 69 6f 6e    many connection
0080  20 65 72 72 6f 72 73 3b 20 75 6e 62 6c 6f 63 6b    errors; unblock
0090  20 77 69 74 68 20 27 6d 79 73 71 6c 61 64 6d 69    with 'mysqladmi
00a0  6e 20 66 6c 75 73 68 2d 68 6f 73 74 73 27         n flush-hosts'

Comment by Haidong Ji [ 2022-01-12 ]

This is great, thanks, @wlad!

I've applied your change to my local 10.6 branch, built and tested it successfully. The new build now provides the correct error packet back to the client when `max_connect_errors` has been reached.

`telnet` example below:

haidong@ryzenkde:~/messAround$ telnet 192.168.1.186 3306
Trying 192.168.1.186...
Connected to 192.168.1.186.
Escape character is '^]'.
nHost '192.168.1.153' is blocked because of many connection errors; unblock with 'mariadb-admin flush-hosts'Connection closed by foreign host.

`pymysql` example below:

haidong@ryzenkde:~/messAround$ python testConn.py 
Traceback (most recent call last):
  File "/home/haidong/messAround/testConn.py", line 3, in <module>
    connection = pymysql.connect(host='192.168.1.186',
  File "/usr/lib/python3.10/site-packages/pymysql/connections.py", line 353, in __init__
    self.connect()
  File "/usr/lib/python3.10/site-packages/pymysql/connections.py", line 632, in connect
    self._get_server_information()
  File "/usr/lib/python3.10/site-packages/pymysql/connections.py", line 1055, in _get_server_information
    packet = self._read_packet()
  File "/usr/lib/python3.10/site-packages/pymysql/connections.py", line 725, in _read_packet
    packet.raise_for_error()
  File "/usr/lib/python3.10/site-packages/pymysql/protocol.py", line 221, in raise_for_error
    err.raise_mysql_exception(self._data)
  File "/usr/lib/python3.10/site-packages/pymysql/err.py", line 143, in raise_mysql_exception
    raise errorclass(errno, errval)
pymysql.err.OperationalError: (1129, "192.168.1.153' is blocked because of many connection errors; unblock with 'mariadb-admin flush-hosts'")

Previously with the bug, the output from `pymysql` is:

pymysql.err.InternalError: Packet sequence number wrong - got 1 expected 0

Generated at Thu Feb 08 09:05:44 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.