Bug #82862 xplugin: server does not seem to respond to "0-sized" messages correctly
Submitted: 5 Sep 2016 16:55 Modified: 24 Jan 2017 12:53
Reporter: Simon Mudd (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Document Store: X Plugin Severity:S3 (Non-critical)
Version:5.7.14 OS:Any
Assigned to: CPU Architecture:Any

[5 Sep 2016 16:55] Simon Mudd
Description:
The basic X protocol specification requires protobuf messages to be sent between client and esrver. These are "wrapped" with a length indicator and message type to indicate the type of protobuf message being exchanged.

While it may not make much sense it is possible to send a zero-length message (4 "\x00" bytes) and consequently there is no space for a message type.

There's no official protocol document yet but it looks like the server does not respond to these messages possibly because it expects at least 5 bytes (the message length + the message type). I'm not sure.

In any case it would be good to document expected behaviour is someone sends this type of message and the server notices this immediately and acts accordingly.

How to repeat:
Send 4-bytes to port 33060 where the xplugin is loaded and see you don't get a response.

I'll upload a test script (written in go). The output is shown here:

$ go run main.go
2016/09/05 18:52:52 connected to: 127.0.0.1:33060
2016/09/05 18:52:52 Wrote 4 bytes indicating zero length message size
2016/09/05 18:52:52 Waiting for 4 bytes of response
2016/09/05 18:53:22 net.Read failed: only read 0 of 4 bytes: EOF
exit status 1

Using wireshark I see no response from the server.

Suggested fix:
Initially I'd expect the "null message" to be useless though I can see it being helpful for "heartbeat type messages" which are only seen at the transport layer but not used outside of that.  There's currently no heartbeat mechanism so that needs a further discussion but I'd expect one of 2 behaviours to be specified and then the server to respond accordingly.

(1) accept the message, treating it as a NULL message and do nothing. That might be what's happening now as I see no response, but the connection does not seem to be dropped.
(2) treat this as a broken message and drop the connection, logging (in counters) the issue and if logging is sufficiently verbose logging a "protocol error".
[5 Sep 2016 16:55] Simon Mudd
Short script to connect to server and send 0-length message.

Attachment: main.go (application/octet-stream, text), 1.04 KiB.

[5 Sep 2016 17:34] Jan Kneschke
$ perl -e 'print("\x00" x 4)' | nc 127.0.0.1 33060 | hd

should produce the same behaviour
[6 Sep 2016 4:37] Umesh Shastry
I'm marking this bug as private until web team removes path from Simon's initial note. Requested web team to remove the same.
[6 Sep 2016 4:58] Umesh Shastry
Hello Simon,

Thank you for the report and test case.

Thanks,
Umesh
[6 Sep 2016 4:59] Umesh Shastry
-- 

ushastry@bugs:~$ go run main.go 
2016/09/06 10:29:37 connected to: 127.0.0.1:33060
2016/09/06 10:29:37 Wrote 4 bytes indicating zero length message size
2016/09/06 10:29:37 Waiting for 4 bytes of response
2016/09/06 10:30:07 net.Read failed: only read 0 of 4 bytes: EOF
exit status 1
[6 Sep 2016 13:36] Vlad Safronov
The path fixed.
[24 Jan 2017 12:53] Tony Bedford
Posted by developer:
 
A entry has been added to the 5.7.17 and 8.0.1 changelogs:

When the client sent a zero length message, the X Plugin did not send a response.                                                                                                      
                                                                                                                                  
For a subsequent message the client received an error E_X_BAD_MESSAGE and was disconnected, depending on the header content.