From 57e3a53c295dd20824fd0537c6ed826482e8c213 Mon Sep 17 00:00:00 2001 From: Rinat Baygildin Date: Thu, 29 Sep 2022 15:10:07 +0300 Subject: [PATCH 1/2] Fix panic of interface conversion The previous commit fd89a9 added extra & on 'put' to the pool. This was the reason of panic on 'get' method: panic: interface conversion: interface {} is **[]uint8, not *[]uint8 Signed-off-by: Rinat Baygildin Change-Id: Icce0ee55ee4439c4d9842f4c1b82878bcc309331 --- adapter/socketclient/socketclient.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/adapter/socketclient/socketclient.go b/adapter/socketclient/socketclient.go index ccaabf52..f9372276 100644 --- a/adapter/socketclient/socketclient.go +++ b/adapter/socketclient/socketclient.go @@ -375,12 +375,15 @@ func (c *Client) writeMsg(msg []byte) error { c.writeMu.Lock() defer c.writeMu.Unlock() - header := c.headerPool.Get().(*[]byte) + header, ok := c.headerPool.Get().(*[]byte) + if !ok { + return fmt.Errorf("failed to get header from pool") + } err := writeMsgHeader(c.writer, *header, len(msg)) if err != nil { return err } - c.headerPool.Put(&header) + c.headerPool.Put(header) if err := writeMsgData(c.writer, msg, c.writer.Size()); err != nil { return err @@ -498,12 +501,15 @@ func (c *Client) readMsgTimeout(buf []byte, timeout time.Duration) ([]byte, erro func (c *Client) readMsg(buf []byte) ([]byte, error) { log.Debug("reading msg..") - header := c.headerPool.Get().(*[]byte) + header, ok := c.headerPool.Get().(*[]byte) + if !ok { + return nil, fmt.Errorf("failed to get header from pool") + } msgLen, err := readMsgHeader(c.reader, *header) if err != nil { return nil, err } - c.headerPool.Put(&header) + c.headerPool.Put(header) msg, err := readMsgData(c.reader, buf, msgLen) if err != nil { From 08808d1d6316310eb5186eb00be171dd29c6070c Mon Sep 17 00:00:00 2001 From: Rinat Baygildin Date: Thu, 29 Sep 2022 15:34:20 +0300 Subject: [PATCH 2/2] Increase reply timeout on tests One millisecond timeout is not enough for ci, increase it to prevent flaps. Signed-off-by: Rinat Baygildin Change-Id: I1534b8ad4ef9e5b76b4fb00213ad377c20083377 Signed-off-by: Rinat Baygildin --- core/channel_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/channel_test.go b/core/channel_test.go index d3773123..674b5fc2 100644 --- a/core/channel_test.go +++ b/core/channel_test.go @@ -190,7 +190,7 @@ func TestSetReplyTimeout(t *testing.T) { ctx := setupTest(t) defer ctx.teardownTest() - ctx.ch.SetReplyTimeout(time.Millisecond) + ctx.ch.SetReplyTimeout(time.Millisecond * 10) // mock reply ctx.mockVpp.MockReply(&ControlPingReply{}) @@ -343,7 +343,7 @@ func TestReceiveReplyAfterTimeout(t *testing.T) { ctx := setupTest(t) defer ctx.teardownTest() - ctx.ch.SetReplyTimeout(time.Millisecond) + ctx.ch.SetReplyTimeout(time.Millisecond * 10) // mock reply ctx.mockVpp.MockReplyWithContext(mock.MsgWithContext{Msg: &ControlPingReply{}, SeqNum: 1})