Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Handling internet connectivity issues when watching reference. #60

Merged
merged 6 commits into from
Nov 12, 2016

Conversation

zabawaba99
Copy link
Owner

Resolves #54.

@zabawaba99
Copy link
Owner Author

@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.

@duyhtq
Copy link

duyhtq commented Oct 6, 2016

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.

@zabawaba99
Copy link
Owner Author

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.

@trongdth
Copy link

trongdth commented Oct 18, 2016

hi @zabawaba99,

your code fixes doesn't work after I turn off my internet 30 mins. I tested 2 cases:

  1. Turn off internet on my PC for 15 mins. Then I turn on and send data, it received but take near 60 seconds to reconnect.
  2. Turn off internet on my PC for 30 mins. Then I turn on and send data, it seems freeze and nothing happens even I wait for 3 mins.

image

Take a look at my attached file.

@zabawaba99
Copy link
Owner Author

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

@rostopira
Copy link

rostopira commented Nov 10, 2016

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 :`(

@zabawaba99
Copy link
Owner Author

@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 firego instead of on the watch function. Ideally, firego would retry requests but I think this is a good first step to resolving the issue at hand.

If you guys have an opportunity, can you please vet this out to ensure that it works on your end as well?

@rostopira
Copy link

rostopira commented Nov 11, 2016

Great, will check it today. Launched on 10:43 (GMT+3), waiting for error

@rostopira
Copy link

No error was thrown. It's silently stopped getting updates

@zabawaba99
Copy link
Owner Author

Can you show me the snippet of could that blocks and what go version you're using?

@rostopira
Copy link

rostopira commented Nov 11, 2016

snippet https://gist.github.com/rostopira/a3f918072a069762aad87fd6c6100a74

$ go version
go version go1.7.1 darwin/amd64

As I said, it's worked perfectly for more than 6 hours, and then suddenly stopped receiving updates (gotPush not called anymore)

@zabawaba99
Copy link
Owner Author

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

@zabawaba99
Copy link
Owner Author

@rostopira I've added a reconnect to the snapshot funcs. They use an exponential backoff right now and only stop reconnecting when you call RemoveEventFunc

@rostopira
Copy link

@zabawaba99 great, will test right now

@rostopira
Copy link

It still works, few hours ago push messages started to duplicate. But I think, problem is in my code
Will tell tomorrow morning (00:40 here) if it still works

@rostopira
Copy link

Even without last commit it works ok. Thank you

@zabawaba99 zabawaba99 merged commit bd23e62 into master Nov 12, 2016
@zabawaba99 zabawaba99 deleted the autoreconnect branch November 12, 2016 15:57
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants