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
.closemethod on the Connection. Before this PR there were two subtly different code paths that a closing connection could take:rethinkdb.corewill derefconn(which is a Connection that implementsderefto deref it's internalconnatom) and destructure the keys of the internalconnatom.send-stop-queryon 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:waitingtoken from the set and continue.closefunction with the conn atom directly.connatom will deref and destructure because it also implements deref.send-querywe 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:
closefunction inside the Connection. People should be able to callcloseand this will use theclosemethod 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.connvariable. The only things that should be mutable are the:waitingand:token, so they could go into atoms.Thoughts?