firebase / firebase/firebase-cpp-sdk

[Bug] Going offline/online after authenticating causes crash

Abierto
#594 3 comentarios 0 reacciones 0 asignados Ver en GitHub
api: database needs-info type: bug
Lenguaje dominante
C++
Estrellas
326
Forks
137
Merge medio
3 d 9 h
PR fusionados (30 d)
5

Descripción

### [REQUIRED] Please fill in the following fields:

* Pre-built SDK from the [website](https://firebase.google.com/download/cpp) or open-source from this repo: open source
* Firebase C++ SDK version: 8.1.0
* Problematic Firebase Component: database
* Other Firebase Components in use: auth
* Platform you are using the C++ SDK on: mac, linux
* Platform you are targeting: desktop

### [REQUIRED] Please describe the issue here:

An assert failure occurs if going offline/online too quickly after being authenticated. Persistent connections do not cancel their "fetch token" async work, and if two run at the same time, the app may crash.

> ASSERT: [...]/firebase-cpp-sdk/database/src/desktop/connection/persistent_connection.cc(578): connection_state_ == kDisconnected

This is problematic for my actual app, as I want to be able to reconnect as soon as the network becomes reachable. If the network becomes unreachable/reachable in rapid succession (very common), it will crash because of this race, which is 100% reproducible.

I noticed that in the ObjC SDK, a guard was added to make sure the "fetch token" routine was still valid when handling its result by using a simple counter. I'd imagine this would have a similarly simple fix.

#### Steps to reproduce:

Have you been able to reproduce this issue with just the [Firebase C++ quickstarts](https://github.com/firebase/quickstart-cpp) ? yes
What's the issue repro rate? 100%

#### Relevant Code:

Add the following to `desktop/testapp/src/common_main.cc` after authenticating (in quickstart-cpp):

```cpp
database->GoOffline();
database->GoOnline();
```

If some time has elapsed after authenticating (e.g., the database is connected), you can still reproduce it if you call GoOffline() / GoOnline() more than once.

```cpp
database->GoOffline();
database->GoOnline();
database->GoOffline();
database->GoOnline();
```

Here's a forked version of quickstart-cpp with the modifications in-place: https://github.com/mikepulaski/quickstart-cpp/tree/auth-token-race

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Reproduce el crash usando desktop/testapp/src/common_main.cc en el ejemplo quickstart-cpp y, después, inspecciona database/src/desktop/connection/persistent_connection.cc alrededor de la aserción indicada. Compara el comportamiento repetido de GoOffline()/GoOnline() con la condición de carrera de fetch-token descrita. Se considera terminado cuando las transiciones rápidas entre offline y online después de la autenticación ya no provoquen la aserción ni el crash.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
cpp
Área
authentication, databases
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.