Skip to content

Conversation

@timvaillancourt
Copy link
Contributor

@timvaillancourt timvaillancourt commented Aug 12, 2018

Under go test with -race the TestUploadOplogToS3 panics. This seems to be due to the session being used in a goroutine that .Open() starts.

Without this PR, you get this panic with go test -race:

test_1       | === RUN   TestUploadOplogToS3
test_1       | panic: Session already closed
test_1       | 
test_1       | goroutine 53 [running]:
test_1       | github.com/globalsign/mgo.(*Session).cluster(0xc4200aa9c0, 0xb1f990)
test_1       | 	/go/src/github.com/globalsign/mgo/session.go:2071 +0xa5
test_1       | github.com/globalsign/mgo.(*Session).acquireSocket(0xc4200aa9c0, 0xa60701, 0x0, 0x0, 0x0)
test_1       | 	/go/src/github.com/globalsign/mgo/session.go:5141 +0x176
test_1       | github.com/globalsign/mgo.(*Database).Run(0xc4203d1d70, 0xa607a0, 0xc421ce0960, 0xa2a9c0, 0xc421cea000, 0x0, 0x0)
test_1       | 	/go/src/github.com/globalsign/mgo/session.go:992 +0x5e
test_1       | github.com/globalsign/mgo.(*Session).Run(0xc4200aa9c0, 0xa607a0, 0xc421ce0960, 0xa2a9c0, 0xc421cea000, 0xc4200ca1f0, 0xc4203d1de0)
test_1       | 	/go/src/github.com/globalsign/mgo/session.go:2489 +0xba
test_1       | github.com/percona/mongodb-backup/internal/cluster.GetIsMaster(0xc4200aa9c0, 0xc400000001, 0x1052, 0x2)
test_1       | 	/go/src/github.com/percona/mongodb-backup/internal/cluster/is_master.go:16 +0x1a3
test_1       | github.com/percona/mongodb-backup/internal/oplog.(*OplogTail).tailQuery(0xc4200ca180, 0x1)
test_1       | 	/go/src/github.com/percona/mongodb-backup/internal/oplog/oplog_tail.go:188 +0x549
test_1       | github.com/percona/mongodb-backup/internal/oplog.(*OplogTail).tail(0xc4200ca180)
test_1       | 	/go/src/github.com/percona/mongodb-backup/internal/oplog/oplog_tail.go:163 +0x4ce
test_1       | created by github.com/percona/mongodb-backup/internal/oplog.open
test_1       | 	/go/src/github.com/percona/mongodb-backup/internal/oplog/oplog_tail.go:86 +0x2b5
test_1       | FAIL	github.com/percona/mongodb-backup/internal/oplog	6.062s

After this PR I no longer get this error, but I'm not sure if the way I fixed this is ideal. @percona-csalguero: what do you think? It's also possible a 'defer' is triggering too early?

This change:

  1. Passes a cloned *mgo.Session into the tailer goroutine .open().
  2. The *OplogTail.Close() closes the cloned-session.

@timvaillancourt timvaillancourt changed the title Clone *mgo.Session (and close it within goroutine) to error with -race test Clone *mgo.Session (and close it within goroutine) to fix error with go test -race Aug 12, 2018
@percona-csalguero percona-csalguero merged commit a05ad05 into master Aug 20, 2018
@percona-csalguero percona-csalguero deleted the oplog_tailer_clone_session branch August 20, 2018 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants