Prevent ready callback from being called after connection error and vice versa