Skip to content

Commit 7397921

Browse files
Merge branch 'master' into GODRIVER-3444
2 parents b2e5cbb + 50cf0c2 commit 7397921

File tree

111 files changed

+16516
-2394
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+16516
-2394
lines changed

bson/marshal.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,10 @@ func MarshalValue(val interface{}) (Type, []byte, error) {
133133
return 0, nil, err
134134
}
135135
typ := sw.Next(2)
136-
return Type(typ[0]), sw.Bytes(), nil
136+
clone := append([]byte{}, sw.Bytes()...) // Don't hand out a shared reference to byte buffer bytes
137+
// and fully copy the data. The byte buffer is (potentially) reused
138+
// and handing out only a reference to the bytes may lead to race-conditions with the buffer.
139+
return Type(typ[0]), clone, nil
137140
}
138141

139142
// MarshalExtJSON returns the extended JSON encoding of val.

bson/marshal_value_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212

1313
"go.mongodb.org/mongo-driver/v2/internal/assert"
14+
"go.mongodb.org/mongo-driver/v2/internal/require"
1415
)
1516

1617
func TestMarshalValue(t *testing.T) {
@@ -33,6 +34,25 @@ func TestMarshalValue(t *testing.T) {
3334
})
3435
}
3536
})
37+
38+
t.Run("returns distinct address ranges", func(t *testing.T) {
39+
// Call MarshalValue in a loop with the same large value (make sure to
40+
// trigger the buffer pooling, which currently doesn't happen for very
41+
// small values). Compare the previous and current BSON byte slices and
42+
// make sure they always have distinct memory ranges.
43+
//
44+
// Don't run this test in parallel to maximize the chance that we get
45+
// the same pooled buffer for most/all calls.
46+
largeVal := strings.Repeat("1234567890", 100_000)
47+
var prev []byte
48+
for i := 0; i < 20; i++ {
49+
_, b, err := MarshalValue(largeVal)
50+
require.NoError(t, err)
51+
52+
assert.DifferentAddressRanges(t, b, prev)
53+
prev = b
54+
}
55+
})
3656
}
3757

3858
func compareMarshalValueResults(t *testing.T, tc marshalValueTestCase, gotType Type, gotBytes []byte) {

docs/migration-2.0.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -503,11 +503,7 @@ mongo.WithSession(context.TODO(),sess,func(ctx context.Context) error {
503503

504504
## Options Package
505505

506-
The following fields were marked for internal use only and do not have replacement:
507-
508-
- `ClientOptions.AuthenticateToAnything`
509-
- `FindOptions.OplogReplay`
510-
- `FindOneOptions.OplogReplay`
506+
`ClientOptions.AuthenticateToAnything` was marked for internal use in 1.x and does not have a replacement.
511507

512508
The following fields were removed because they are no longer supported by the server
513509

@@ -844,7 +840,7 @@ The `bson/primitive` package has been merged into the `bson` package.
844840
845841
Additionally, the `bson.D` has implemented the `json.Marshaler` and `json.Unmarshaler` interfaces, where it uses a key-value representation in "regular" (i.e. non-Extended) JSON.
846842
847-
The `bson.D.String` and `bson.M.String` methods return a relaxed Extended JSON representation of the document.
843+
The `bson.D.String` and `bson.M.String` methods return an Extended JSON representation of the document.
848844
849845
```go
850846
// v2

examples/_logger/logrus/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ require (
1818
github.com/xdg-go/scram v1.1.2 // indirect
1919
github.com/xdg-go/stringprep v1.0.4 // indirect
2020
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
21-
golang.org/x/crypto v0.31.0 // indirect
21+
golang.org/x/crypto v0.32.0 // indirect
2222
golang.org/x/sync v0.10.0 // indirect
23-
golang.org/x/sys v0.28.0 // indirect
23+
golang.org/x/sys v0.29.0 // indirect
2424
golang.org/x/text v0.21.0 // indirect
2525
)

examples/_logger/logrus/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
3030
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
3131
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3232
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
33-
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
34-
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
33+
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
34+
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
3535
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
3636
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3737
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -46,8 +46,8 @@ golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBc
4646
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4747
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4848
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
49-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
50-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
49+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
50+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5151
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
5252
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
5353
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

examples/_logger/zap/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
2121
go.uber.org/atomic v1.7.0 // indirect
2222
go.uber.org/multierr v1.6.0 // indirect
23-
golang.org/x/crypto v0.31.0 // indirect
23+
golang.org/x/crypto v0.32.0 // indirect
2424
golang.org/x/sync v0.10.0 // indirect
2525
golang.org/x/text v0.21.0 // indirect
2626
)

examples/_logger/zap/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
4848
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
4949
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5050
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
51-
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
52-
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
51+
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
52+
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
5353
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
5454
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
5555
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=

examples/_logger/zerolog/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ require (
2020
github.com/xdg-go/scram v1.1.2 // indirect
2121
github.com/xdg-go/stringprep v1.0.4 // indirect
2222
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
23-
golang.org/x/crypto v0.31.0 // indirect
23+
golang.org/x/crypto v0.32.0 // indirect
2424
golang.org/x/sync v0.10.0 // indirect
25-
golang.org/x/sys v0.28.0 // indirect
25+
golang.org/x/sys v0.29.0 // indirect
2626
golang.org/x/text v0.21.0 // indirect
2727
)

examples/_logger/zerolog/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfS
3131
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
3232
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3333
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
34-
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
35-
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
34+
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
35+
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
3636
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
3737
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
3838
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
@@ -48,8 +48,8 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc
4848
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4949
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5050
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
51-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
52-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
51+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
52+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5353
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
5454
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
5555
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/xdg-go/scram v1.1.2
1111
github.com/xdg-go/stringprep v1.0.4
1212
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78
13-
golang.org/x/crypto v0.31.0
13+
golang.org/x/crypto v0.32.0
1414
golang.org/x/sync v0.10.0
1515
)
1616

0 commit comments

Comments
 (0)