Skip to content

Commit 84649b9

Browse files
committed
Fixed stop query incorrectly waiting for response
1 parent 739cf16 commit 84649b9

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1616
- Fixed `Decode` no longer setting pointer to nil on document not found
1717
- Fixed panic when `fetchMore` returns an error
1818
- Fixed deadlock when closing changefeed
19+
- Fixed stop query incorrectly waiting for response
1920

2021
## v1.1.3
2122
### Fixed

cursor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ func (c *Cursor) Close() error {
119119
q := Query{
120120
Type: p.Query_STOP,
121121
Token: c.token,
122+
Opts: map[string]interface{}{
123+
"noreply": true,
124+
},
122125
}
123126

124-
c.mu.Unlock()
125127
_, _, err = conn.Query(q)
126-
c.mu.Lock()
127128
}
128129

129130
if c.releaseConn != nil {

query_table_test.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,41 @@ func (s *RethinkSuite) TestTableChangesExit(c *test.C) {
264264
for _ = range change {
265265
n++
266266
}
267-
if res.Err() != nil {
268-
c.Fatal(res.Err())
267+
if res.Err() == nil {
268+
c.Fatal("No error returned, expected connection closed")
269269
}
270270

271271
c.Assert(n, test.Equals, 5)
272272
}
273+
274+
func (s *RethinkSuite) TestTableChangesExitNoResults(c *test.C) {
275+
DB("test").TableDrop("changes").Exec(session)
276+
DB("test").TableCreate("changes").Exec(session)
277+
278+
var n int
279+
280+
res, err := DB("test").Table("changes").Changes().Run(session)
281+
if err != nil {
282+
c.Fatal(err.Error())
283+
}
284+
c.Assert(res.Type(), test.Equals, "Feed")
285+
286+
change := make(chan ChangeResponse)
287+
288+
// Close cursor after one second
289+
go func() {
290+
<-time.After(time.Second)
291+
res.Close()
292+
}()
293+
294+
// Listen for changes
295+
res.Listen(change)
296+
for _ = range change {
297+
n++
298+
}
299+
if res.Err() == nil {
300+
c.Fatal("No error returned, expected connection closed")
301+
}
302+
303+
c.Assert(n, test.Equals, 0)
304+
}

0 commit comments

Comments
 (0)