Skip to content

Commit c3b81bb

Browse files
Roberto Santalladomodwyer
Roberto Santalla
authored andcommitted
Allow passing slice pointer as an interface pointer to Iter.All (#181)
* socket: only send client metadata once per socket (#105) Periodic cluster synchronisation calls isMaster() which currently resends the "client" metadata every call - the spec specifies: isMaster commands issued after the initial connection handshake MUST NOT contain handshake arguments https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake This hotfix prevents subsequent isMaster calls from sending the client metadata again - fixes #101 and fixes #103. Thanks to @changwoo-nam @qhenkart @canthefason @jyoon17 for spotting the initial issue, opening tickets, and having the problem debugged with a PoC fix before I even woke up. * Merge Development (#111) * Brings in a patch on having flusher not suppress errors. (#81) go-mgo#360 * Fallback to JSON tags when BSON tag isn't present (#91) * Fallback to JSON tags when BSON tag isn't present Cleanup. * Add test to demonstrate tagging fallback. - Test coverage for tagging test. * socket: only send client metadata once per socket Periodic cluster synchronisation calls isMaster() which currently resends the "client" metadata every call - the spec specifies: isMaster commands issued after the initial connection handshake MUST NOT contain handshake arguments https://github.com/mongodb/specifications/blob/master/source/mongodb-handshake/handshake.rst#connection-handshake This hotfix prevents subsequent isMaster calls from sending the client metadata again - fixes #101 and fixes #103. Thanks to @changwoo-nam @qhenkart @canthefason @jyoon17 for spotting the initial issue, opening tickets, and having the problem debugged with a PoC fix before I even woke up. * Cluster abended test 254 (#100) * Add a test that mongo Server gets their abended reset as necessary. See https://github.com/go-mgo/mgo/issues/254 and https://github.com/go-mgo/mgo/pull/255/files * Include the patch from Issue 255. This brings in a test which fails without the patch, and passes with the patch. Still to be tested, manual tcpkill of a socket. * changeStream support (#97) Add $changeStream support * readme: credit @peterdeka and @steve-gray (#110) * Hotfix #120 (#136) * cluster: fix deadlock in cluster synchronisation (#120) For a impressively thorough breakdown of the problem, see: #120 (comment) Huge thanks to @dvic and @KJTsanaktsidis for the report and fix. * readme: credit @dvic and @KJTsanaktsidis * Allow passing slice pointer as an interface pointer to Iter.All * Reverted to original error message, added test case for interface{} ptr
1 parent 7253b2b commit c3b81bb

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
_harness
2-
.vscode
2+
.vscode

session.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,6 @@ type Index struct {
14531453
// Collation allows users to specify language-specific rules for string comparison,
14541454
// such as rules for lettercase and accent marks.
14551455
type Collation struct {
1456-
14571456
// Locale defines the collation locale.
14581457
Locale string `bson:"locale"`
14591458

@@ -4408,10 +4407,19 @@ func (iter *Iter) Next(result interface{}) bool {
44084407
//
44094408
func (iter *Iter) All(result interface{}) error {
44104409
resultv := reflect.ValueOf(result)
4411-
if resultv.Kind() != reflect.Ptr || resultv.Elem().Kind() != reflect.Slice {
4410+
if resultv.Kind() != reflect.Ptr {
44124411
panic("result argument must be a slice address")
44134412
}
4413+
44144414
slicev := resultv.Elem()
4415+
4416+
if slicev.Kind() == reflect.Interface {
4417+
slicev = slicev.Elem()
4418+
}
4419+
if slicev.Kind() != reflect.Slice {
4420+
panic("result argument must be a slice address")
4421+
}
4422+
44154423
slicev = slicev.Slice(0, slicev.Cap())
44164424
elemt := slicev.Type().Elem()
44174425
i := 0

session_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,18 @@ func (s *S) TestInsertFindAll(c *C) {
453453
// Ensure result is backed by the originally allocated array
454454
c.Assert(&result[0], Equals, &allocd[0])
455455

456+
// Re-run test destination as a pointer to interface{}
457+
var resultInterface interface{}
458+
459+
anotherslice := make([]R, 5)
460+
resultInterface = anotherslice
461+
err = coll.Find(nil).Sort("a").All(&resultInterface)
462+
c.Assert(err, IsNil)
463+
assertResult()
464+
465+
// Ensure result is backed by the originally allocated array
466+
c.Assert(&result[0], Equals, &allocd[0])
467+
456468
// Non-pointer slice error
457469
f := func() { coll.Find(nil).All(result) }
458470
c.Assert(f, Panics, "result argument must be a slice address")

0 commit comments

Comments
 (0)