diff --git a/protocol/protocol.go b/protocol/protocol.go index 86d05b594..82cb46d22 100644 --- a/protocol/protocol.go +++ b/protocol/protocol.go @@ -192,6 +192,10 @@ func (c *Connection) readerLoop() { c.close() break } + if hdr.version != 0 { + c.close() + break + } c.wLock.Lock() c.lastReceive = time.Now() diff --git a/protocol/protocol_test.go b/protocol/protocol_test.go index 4492df25f..c0cb8a945 100644 --- a/protocol/protocol_test.go +++ b/protocol/protocol_test.go @@ -135,3 +135,25 @@ func TestRequestResponseErr(t *testing.T) { t.Error("Never passed") } } + +func TestVersionErr(t *testing.T) { + m0 := &TestModel{} + m1 := &TestModel{} + + ar, aw := io.Pipe() + br, bw := io.Pipe() + + c0 := NewConnection("c0", ar, bw, m0) + NewConnection("c1", br, aw, m1) + + c0.mwriter.writeHeader(header{ + version: 2, + msgID: 0, + msgType: 0, + }) + c0.flush() + + if !m1.closed { + t.Error("Connection should close due to unknown version") + } +}