Avoid double erroring of callbacks

Under certain conditions, when a connection was closed by the server,
the close() method would first be called, followed by the defunct()
method shortly afterwards.  Both of these would error out all callbacks.

This avoids doing "defunct" work if the connection is already closed,
and holds a lock to avoid any other race conditions which might result
in erroring all callbacks twice.