-
Notifications
You must be signed in to change notification settings - Fork 80
Handling internet connectivity issues when watching reference. #60
Conversation
@duyhtq could you give this branch a try? I tried it locally and it looks like when the internet comes back on, the connection is reestablished. I used: func main() {
gen := fireauth.New("secret")
t, err := gen.CreateToken(fireauth.Data{"uid": "foo"}, nil)
if err != nil {
log.Fatal(err)
}
fb := firego.New("https://foo.firebaseio.com/", nil)
fb.Auth(t)
events := make(chan firego.Event)
if err := fb.Watch(events); err != nil {
log.Fatal(err)
}
fmt.Println("Starting")
for event := range events {
log.Printf("New event: %#v\n", event)
}
fmt.Println("Exited")
} After the connection was established, I killed the internet for 5 minutes and when it came back on the keep-alive messages came through again. |
hey @zabawaba99 thanks for the the reply. it looks like it's pretty standard fireauth and firego code as in your official documentation example? if so, my code is very similar. the problem usually don't occur if you only turn it back on after 5 mins. try to turn it offline for a little longer (say 20 mins - 30 mins), and the problem will "likely" to occur. it's pretty inconsistent, but it usually happens to me if i leave it offline for a while (like overnight) and i can't send message to it in the morning. |
I'll do some more testing with this branch and leave it over long periods of time to see if I can get it to happen on my end. This branch uses some different functions for scanning which I think may help. When I tried the same sample code in master, it wouldn't work. |
hi @zabawaba99, your code fixes doesn't work after I turn off my internet 30 mins. I tested 2 cases:
Take a look at my attached file. |
Thanks for the test case @trongdth . I'll make sure I can replicate the same test cases on my end and see if I can address this |
2f18505
to
558eb1e
Compare
558eb1e
to
d64f22e
Compare
Tried this branch. I'm using this lib on virtual hosting, and I'm not sure, that they have stable connection. But it stop's receiving updates in different interval. Sometimes it's 6 hours, sometimes just 2. With master branch it stops updating in interval 6-48 hours. Can't release my app w/o this fix :`( |
… not being picked up by the bytes reader
@rostopira @duyhtq I added a heartbeat to the watch connection which will cause the notifications channel to send an error event and close if Firebase doesn't send anything down (including the keep-alive) for 2 minutes. This would put the retry logic onto the consumers of If you guys have an opportunity, can you please vet this out to ensure that it works on your end as well? |
Great, will check it today. Launched on 10:43 (GMT+3), waiting for error |
No error was thrown. It's silently stopped getting updates |
Can you show me the snippet of could that blocks and what go version you're using? |
snippet https://gist.github.com/rostopira/a3f918072a069762aad87fd6c6100a74
As I said, it's worked perfectly for more than 6 hours, and then suddenly stopped receiving updates (gotPush not called anymore) |
Got it, that makes a lot more sense. Those handler funcs will not work without the reconnect. I think we can make these reconnect relatively easily. Give me a little bit |
@rostopira I've added a reconnect to the snapshot funcs. They use an exponential backoff right now and only stop reconnecting when you call |
@zabawaba99 great, will test right now |
It still works, few hours ago push messages started to duplicate. But I think, problem is in my code |
Even without last commit it works ok. Thank you |
Resolves #54.