Check that the connection hasn't been closed already before calling
the onConnection callback.