Fix close method on Connection to use this
#50
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a pretty subtle bug, you will only run into it when you try to close a connection which has queries outstanding (e.g. changefeeds) using the
.close
method on the Connection. Before this PR there were two subtly different code paths that a closing connection could take:rethinkdb.core
will derefconn
(which is a Connection that implementsderef
to deref it's internalconn
atom) and destructure the keys of the internalconn
atom.send-stop-query
on every outstanding query, we pass the Connection.send-query
, we access the connection atom (without derefing it) by calling(:conn conn)
on the record.swap!
to remove the:waiting
token from the set and continue.close
function with the conn atom directly.conn
atom will deref and destructure because it also implements deref.send-query
we are trying to call(:conn conn)
on the atom which will return nil.swap!
will throw a NPE.I'm not sure whether this is a breaking change or not, it fixes the behaviour of
.close
, so it's worth at least highlighting in the changelog and release notes.There's two things we could do to make this kind of bug not happen in the future:
close
function inside the Connection. People should be able to callclose
and this will use theclose
method on the Connection. However in my limited testing this doesn't seem to be happening. I'm not quite sure why, I thought records defined their methods as functions in the ns they were defined in.conn
variable. The only things that should be mutable are the:waiting
and:token
, so they could go into atoms.Thoughts?