Skip to content

Commit 3f82dc1

Browse files
author
Christopher Swenson
authored
Merge pull request #292 from hashicorp/vault-19781/msgpack-upgrade
Upgrade to go-msgpack/v2 2.1.1
2 parents 8ddac56 + eb70f1f commit 3f82dc1

11 files changed

+85
-54
lines changed

.github/workflows/check.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
GO_VERSION: [ "1.16","1.17","1.18" ]
18+
GO_VERSION: [ "1.20","1.21" ]
1919
steps:
2020
- name: "Fetch source code"
2121
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
@@ -45,7 +45,7 @@ jobs:
4545
runs-on: ubuntu-latest
4646
strategy:
4747
matrix:
48-
GO_VERSION: [ "1.16","1.17","1.18" ]
48+
GO_VERSION: [ "1.20","1.21" ]
4949
steps:
5050
- name: "Fetch source code"
5151
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
@@ -76,7 +76,7 @@ jobs:
7676
runs-on: ubuntu-latest
7777
strategy:
7878
matrix:
79-
GO_VERSION: [ "1.16","1.17","1.18" ]
79+
GO_VERSION: [ "1.20","1.21" ]
8080
steps:
8181
- name: "Fetch source code"
8282
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0
@@ -107,7 +107,7 @@ jobs:
107107
runs-on: ubuntu-latest
108108
strategy:
109109
matrix:
110-
GO_VERSION: [ "1.16","1.17","1.18" ]
110+
GO_VERSION: [ "1.20","1.21" ]
111111
steps:
112112
- name: "Fetch source code"
113113
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0

broadcast.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (m *Memberlist) encodeAndBroadcast(node string, msgType messageType, msg in
5858
// and notifies the given channel when transmission is finished. Fails
5959
// silently if there is an encoding error.
6060
func (m *Memberlist) encodeBroadcastNotify(node string, msgType messageType, msg interface{}, notify chan struct{}) {
61-
buf, err := encode(msgType, msg)
61+
buf, err := encode(msgType, msg, m.config.MsgpackUseNewTimeFormat)
6262
if err != nil {
6363
m.logger.Printf("[ERR] memberlist: Failed to encode message for broadcast: %s", err)
6464
} else {

config.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/armon/go-metrics"
16-
multierror "github.com/hashicorp/go-multierror"
16+
"github.com/hashicorp/go-multierror"
1717
)
1818

1919
type Config struct {
@@ -260,6 +260,12 @@ type Config struct {
260260
// QueueCheckInterval is the interval at which we check the message
261261
// queue to apply the warning and max depth.
262262
QueueCheckInterval time.Duration
263+
264+
// MsgpackUseNewTimeFormat when set to true, force the underlying msgpack
265+
// codec to use the new format of time.Time when encoding (used in
266+
// go-msgpack v1.1.5 by default). Decoding is not affected, as all
267+
// go-msgpack v2.1.0+ decoders know how to decode both formats.
268+
MsgpackUseNewTimeFormat bool
263269
}
264270

265271
// ParseCIDRs return a possible empty list of all Network that have been parsed

go.mod

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
module github.com/hashicorp/memberlist
22

3-
go 1.12
3+
go 1.20
44

55
require (
66
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da
7-
github.com/davecgh/go-spew v1.1.1 // indirect
87
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c
9-
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
10-
github.com/hashicorp/go-msgpack v0.5.3
8+
github.com/hashicorp/go-msgpack/v2 v2.1.1
119
github.com/hashicorp/go-multierror v1.0.0
1210
github.com/hashicorp/go-sockaddr v1.0.0
1311
github.com/miekg/dns v1.1.26
14-
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect
15-
github.com/pmezard/go-difflib v1.0.0 // indirect
1612
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529
1713
github.com/stretchr/testify v1.2.2
18-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
14+
)
15+
16+
require (
17+
github.com/davecgh/go-spew v1.1.1 // indirect
18+
github.com/hashicorp/errwrap v1.0.0 // indirect
19+
github.com/hashicorp/go-immutable-radix v1.0.0 // indirect
20+
github.com/hashicorp/golang-lru v0.5.0 // indirect
21+
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect
22+
github.com/pmezard/go-difflib v1.0.0 // indirect
23+
golang.org/x/crypto v0.14.0 // indirect
24+
golang.org/x/net v0.16.0 // indirect
25+
golang.org/x/sys v0.13.0 // indirect
1926
)

go.sum

+8-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/U
88
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
99
github.com/hashicorp/go-immutable-radix v1.0.0 h1:AKDB1HM5PWEA7i4nhcpwOrO2byshxBjXVn/J/3+z5/0=
1010
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
11-
github.com/hashicorp/go-msgpack v0.5.3 h1:zKjpN5BK/P5lMYrLmBHdBULWbJ0XpYR+7NGzqkZzoD4=
12-
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
11+
github.com/hashicorp/go-msgpack/v2 v2.1.1 h1:xQEY9yB2wnHitoSzk/B9UjXWRQ67QKu5AOm8aFp8N3I=
12+
github.com/hashicorp/go-msgpack/v2 v2.1.1/go.mod h1:upybraOAblm4S7rx0+jeNy+CWWhzywQsSRV5033mMu4=
1313
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
1414
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
1515
github.com/hashicorp/go-sockaddr v1.0.0 h1:GeH6tui99pF4NJgfnhp+L6+FfobzVW3Ah46sLo0ICXs=
@@ -29,19 +29,21 @@ github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg
2929
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
3030
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
3131
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
32-
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
3332
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
33+
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
34+
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
3435
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3536
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
36-
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
3737
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
38+
golang.org/x/net v0.16.0 h1:7eBu7KsSvFDtSXUIDbh3aqlK4DPsZ1rByC8PFfBThos=
39+
golang.org/x/net v0.16.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
3840
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
3941
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
4042
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4143
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
4244
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
43-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
44-
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
45+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
46+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4547
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4648
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
4749
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

memberlist.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"time"
3232

3333
"github.com/armon/go-metrics"
34-
multierror "github.com/hashicorp/go-multierror"
35-
sockaddr "github.com/hashicorp/go-sockaddr"
34+
"github.com/hashicorp/go-multierror"
35+
"github.com/hashicorp/go-sockaddr"
3636
"github.com/miekg/dns"
3737
)
3838

net.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import (
1515
"sync/atomic"
1616
"time"
1717

18-
metrics "github.com/armon/go-metrics"
19-
"github.com/hashicorp/go-msgpack/codec"
18+
"github.com/armon/go-metrics"
19+
"github.com/hashicorp/go-msgpack/v2/codec"
2020
)
2121

2222
// This is the minimum and maximum protocol version that we can
@@ -271,7 +271,7 @@ func (m *Memberlist) handleConn(conn net.Conn) {
271271
m.logger.Printf("[ERR] memberlist: failed to receive: %s %s", err, LogConn(conn))
272272

273273
resp := errResp{err.Error()}
274-
out, err := encode(errMsg, &resp)
274+
out, err := encode(errMsg, &resp, m.config.MsgpackUseNewTimeFormat)
275275
if err != nil {
276276
m.logger.Printf("[ERR] memberlist: Failed to encode error response: %s", err)
277277
return
@@ -330,7 +330,7 @@ func (m *Memberlist) handleConn(conn net.Conn) {
330330
}
331331

332332
ack := ackResp{p.SeqNo, nil}
333-
out, err := encode(ackRespMsg, &ack)
333+
out, err := encode(ackRespMsg, &ack, m.config.MsgpackUseNewTimeFormat)
334334
if err != nil {
335335
m.logger.Printf("[ERR] memberlist: Failed to encode ack: %s", err)
336336
return
@@ -773,7 +773,7 @@ func (m *Memberlist) handleCompressed(buf []byte, from net.Addr, timestamp time.
773773

774774
// encodeAndSendMsg is used to combine the encoding and sending steps
775775
func (m *Memberlist) encodeAndSendMsg(a Address, msgType messageType, msg interface{}) error {
776-
out, err := encode(msgType, msg)
776+
out, err := encode(msgType, msg, m.config.MsgpackUseNewTimeFormat)
777777
if err != nil {
778778
return err
779779
}
@@ -819,7 +819,7 @@ func (m *Memberlist) rawSendMsgPacket(a Address, node *Node, msg []byte) error {
819819

820820
// Check if we have compression enabled
821821
if m.config.EnableCompression {
822-
buf, err := compressPayload(msg)
822+
buf, err := compressPayload(msg, m.config.MsgpackUseNewTimeFormat)
823823
if err != nil {
824824
m.logger.Printf("[WARN] memberlist: Failed to compress payload: %v", err)
825825
} else {
@@ -882,7 +882,7 @@ func (m *Memberlist) rawSendMsgPacket(a Address, node *Node, msg []byte) error {
882882
func (m *Memberlist) rawSendMsgStream(conn net.Conn, sendBuf []byte, streamLabel string) error {
883883
// Check if compression is enabled
884884
if m.config.EnableCompression {
885-
compBuf, err := compressPayload(sendBuf)
885+
compBuf, err := compressPayload(sendBuf, m.config.MsgpackUseNewTimeFormat)
886886
if err != nil {
887887
m.logger.Printf("[ERROR] memberlist: Failed to compress payload: %v", err)
888888
} else {
@@ -930,7 +930,11 @@ func (m *Memberlist) sendUserMsg(a Address, sendBuf []byte) error {
930930
}
931931

932932
header := userMsgHeader{UserMsgLen: len(sendBuf)}
933-
hd := codec.MsgpackHandle{}
933+
hd := codec.MsgpackHandle{
934+
BasicHandle: codec.BasicHandle{
935+
TimeNotBuiltin: !m.config.MsgpackUseNewTimeFormat,
936+
},
937+
}
934938
enc := codec.NewEncoder(bufConn, &hd)
935939
if err := enc.Encode(&header); err != nil {
936940
return err
@@ -1340,7 +1344,7 @@ func (m *Memberlist) sendPingAndWaitForAck(a Address, ping ping, deadline time.T
13401344
defer conn.Close()
13411345
conn.SetDeadline(deadline)
13421346

1343-
out, err := encode(pingMsg, &ping)
1347+
out, err := encode(pingMsg, &ping, m.config.MsgpackUseNewTimeFormat)
13441348
if err != nil {
13451349
return false, err
13461350
}

net_test.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"testing"
1717
"time"
1818

19-
"github.com/hashicorp/go-msgpack/codec"
19+
"github.com/hashicorp/go-msgpack/v2/codec"
2020
"github.com/stretchr/testify/require"
2121
)
2222

@@ -43,7 +43,7 @@ func TestHandleCompoundPing(t *testing.T) {
4343
SourcePort: uint16(udpAddr.Port),
4444
SourceNode: "test",
4545
}
46-
buf, err := encode(pingMsg, ping)
46+
buf, err := encode(pingMsg, ping, m.config.MsgpackUseNewTimeFormat)
4747
if err != nil {
4848
t.Fatalf("unexpected err %s", err)
4949
}
@@ -112,7 +112,7 @@ func TestHandlePing(t *testing.T) {
112112
SourcePort: uint16(udpAddr.Port),
113113
SourceNode: "test",
114114
}
115-
buf, err := encode(pingMsg, ping)
115+
buf, err := encode(pingMsg, ping, m.config.MsgpackUseNewTimeFormat)
116116
if err != nil {
117117
t.Fatalf("unexpected err %s", err)
118118
}
@@ -177,7 +177,7 @@ func TestHandlePing_WrongNode(t *testing.T) {
177177
SourcePort: uint16(udpAddr.Port),
178178
SourceNode: "test",
179179
}
180-
buf, err := encode(pingMsg, ping)
180+
buf, err := encode(pingMsg, ping, m.config.MsgpackUseNewTimeFormat)
181181
if err != nil {
182182
t.Fatalf("unexpected err %s", err)
183183
}
@@ -221,7 +221,7 @@ func TestHandleIndirectPing(t *testing.T) {
221221
SourcePort: uint16(udpAddr.Port),
222222
SourceNode: "test",
223223
}
224-
buf, err := encode(indirectPingMsg, &ind)
224+
buf, err := encode(indirectPingMsg, &ind, m.config.MsgpackUseNewTimeFormat)
225225
if err != nil {
226226
t.Fatalf("unexpected err %s", err)
227227
}
@@ -333,7 +333,7 @@ func TestTCPPing(t *testing.T) {
333333
}
334334

335335
ack := ackResp{pingIn.SeqNo, nil}
336-
out, err := encode(ackRespMsg, &ack)
336+
out, err := encode(ackRespMsg, &ack, m.config.MsgpackUseNewTimeFormat)
337337
if err != nil {
338338
pingErrCh <- fmt.Errorf("failed to encode ack: %s", err)
339339
return
@@ -381,7 +381,7 @@ func TestTCPPing(t *testing.T) {
381381
}
382382

383383
ack := ackResp{pingIn.SeqNo + 1, nil}
384-
out, err := encode(ackRespMsg, &ack)
384+
out, err := encode(ackRespMsg, &ack, m.config.MsgpackUseNewTimeFormat)
385385
if err != nil {
386386
pingErrCh <- fmt.Errorf("failed to encode ack: %s", err)
387387
return
@@ -423,7 +423,7 @@ func TestTCPPing(t *testing.T) {
423423
}
424424

425425
bogus := indirectPingReq{}
426-
out, err := encode(indirectPingMsg, &bogus)
426+
out, err := encode(indirectPingMsg, &bogus, m.config.MsgpackUseNewTimeFormat)
427427
if err != nil {
428428
pingErrCh <- fmt.Errorf("failed to encode bogus msg: %s", err)
429429
return
@@ -507,7 +507,11 @@ func TestTCPPushPull(t *testing.T) {
507507

508508
// Send our node state
509509
header := pushPullHeader{Nodes: 3}
510-
hd := codec.MsgpackHandle{}
510+
hd := codec.MsgpackHandle{
511+
BasicHandle: codec.BasicHandle{
512+
TimeNotBuiltin: !m.config.MsgpackUseNewTimeFormat,
513+
},
514+
}
511515
enc := codec.NewEncoder(conn, &hd)
512516

513517
// Send the push/pull indicator
@@ -529,7 +533,11 @@ func TestTCPPushPull(t *testing.T) {
529533
}
530534

531535
var bufConn io.Reader = conn
532-
msghd := codec.MsgpackHandle{}
536+
msghd := codec.MsgpackHandle{
537+
BasicHandle: codec.BasicHandle{
538+
TimeNotBuiltin: !m.config.MsgpackUseNewTimeFormat,
539+
},
540+
}
533541
dec := codec.NewDecoder(bufConn, &msghd)
534542

535543
// Check if we have a compressed message
@@ -620,7 +628,7 @@ func TestSendMsg_Piggyback(t *testing.T) {
620628
SourcePort: uint16(udpAddr.Port),
621629
SourceNode: "test",
622630
}
623-
buf, err := encode(pingMsg, ping)
631+
buf, err := encode(pingMsg, ping, m.config.MsgpackUseNewTimeFormat)
624632
if err != nil {
625633
t.Fatalf("unexpected err %s", err)
626634
}

state.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"sync/atomic"
1414
"time"
1515

16-
metrics "github.com/armon/go-metrics"
16+
"github.com/armon/go-metrics"
1717
)
1818

1919
type NodeStateType int
@@ -356,14 +356,14 @@ func (m *Memberlist) probeNode(node *nodeState) {
356356
}
357357
} else {
358358
var msgs [][]byte
359-
if buf, err := encode(pingMsg, &ping); err != nil {
359+
if buf, err := encode(pingMsg, &ping, m.config.MsgpackUseNewTimeFormat); err != nil {
360360
m.logger.Printf("[ERR] memberlist: Failed to encode UDP ping message: %s", err)
361361
return
362362
} else {
363363
msgs = append(msgs, buf.Bytes())
364364
}
365365
s := suspect{Incarnation: node.Incarnation, Node: node.Name, From: m.config.Name}
366-
if buf, err := encode(suspectMsg, &s); err != nil {
366+
if buf, err := encode(suspectMsg, &s, m.config.MsgpackUseNewTimeFormat); err != nil {
367367
m.logger.Printf("[ERR] memberlist: Failed to encode suspect message: %s", err)
368368
return
369369
} else {

0 commit comments

Comments
 (0)