rethinkdb / rethinkdb-go

Go language driver for RethinkDB
Apache License 2.0
1.65k stars 182 forks source link

Connection pool is not safe #497

Closed CodyDWJones closed 2 years ago

CodyDWJones commented 3 years ago

Describe the bug The connection pool is only useful when writing concurrent code, but it doesn't actually stop multiple goroutines from accessing the same connection simultaneously.

To Reproduce The PR includes a test suite that reproduces the issue with the old Pool code, so long as it's edited to include the afterAcquire and beforeRelease test hooks.

Expected behavior

Screenshots n/a

System info n/a

Additional context Problems with the prior pool implementation:

Suppose pointer == 9 and len(conns) == 10. Three goroutines could run in this sequence:

GR 1: pointer=10                pointer=0                uses conns[0]
GR 2:              pointer=11                            uses conns[1]
GR 3:                                       pointer=1    uses conns[1]
      ---------time------->

Because there is no "in use" check, two of the goroutines end up using the same Connection.

srh commented 3 years ago

It sounds like a legitimate bug report. I don't have a timeline for a fix.

CodyDWJones commented 3 years ago

I have just submitted a proposed fix in #498.

CodyDWJones commented 2 years ago

Not an issue; the Connection and Cursor docs say they do not support concurrent calls, but those comments are very old and aren't actually true.