Use object equality for closing connections for tokens.

Fixes #1540.