Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart after x 'Heartbeat missed, retrying' messages #4

Open
mattparkes opened this issue Jul 19, 2016 · 4 comments
Open

Restart after x 'Heartbeat missed, retrying' messages #4

mattparkes opened this issue Jul 19, 2016 · 4 comments

Comments

@mattparkes
Copy link

I get an issue where after a while I just get a constant stream of 'Heartbeat missed, retrying' with no successful attempts in between. I just Ctrl+C and restart to resolve the issue, but it would be nice if the app could detect say 30 failed heartbeats in a row and then restart.

@quazm
Copy link

quazm commented Jul 19, 2016

Same here.

@padmanek
Copy link

same problem

@minthat
Copy link

minthat commented Jul 19, 2016

Yep! Get it too.

@minthat
Copy link

minthat commented Jul 19, 2016

Here is the current Heartbeat code:

def raw_heartbeat(api_endpoint, access_token, response):
    m4 = pokemon_pb2.RequestEnvelop.Requests()
    m = pokemon_pb2.RequestEnvelop.MessageSingleInt()
    m.f1 = int(time.time() * 1000)
    m4.message = m.SerializeToString()
    m5 = pokemon_pb2.RequestEnvelop.Requests()
    m = pokemon_pb2.RequestEnvelop.MessageSingleString()
    m.bytes = "05daf51635c82611d1aac95c0b051d3ec088a930"
    m5.message = m.SerializeToString()

    walk = sorted(getNeighbors())

    m1 = pokemon_pb2.RequestEnvelop.Requests()
    m1.type = 106
    m = pokemon_pb2.RequestEnvelop.MessageQuad()
    m.f1 = ''.join(map(encode, walk))
    m.f2 = "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
    m.lat = COORDS_LATITUDE
    m.long = COORDS_LONGITUDE
    m1.message = m.SerializeToString()
    response = get_profile(
        access_token,
        api_endpoint,
        response.unknown7,
        m1,
        pokemon_pb2.RequestEnvelop.Requests(),
        m4,
        pokemon_pb2.RequestEnvelop.Requests(),
        m5)
    payload = response.payload[0]
    heartbeat = pokemon_pb2.ResponseEnvelop.HeartbeatPayload()
    heartbeat.ParseFromString(payload)
    return heartbeat

def heartbeat(api_endpoint, access_token, response):
    while True:
        try:
            h = raw_heartbeat(api_endpoint, access_token, response)
            return h
        except Exception, e:
            if DEBUG:
                print(e)
            print('[-] Heartbeat missed, retrying')

Step 1 is to figure out why the heartbeat fails (raw_heartbeat). Is the PGO server ending sessions that aren't active (moving around)? If so, you could add a minor walking distance to the script so that the location moves around. If there isn't a way to find out what's causing the session to timeout or if the cause is not something that can be fixed, consider adding a quick attempts clause to heartbeat so that it restarts the necessary portions of the script (like login?), no need to have the whole damn thing restart! Something along these lines, I'm guessing:

Attempts = 0
while attempts < 3:
    try:
        #heartbeat_raw code
    except Exception, e:
            if DEBUG:
                attempts += 1
                print(e)
            print('[-] Heartbeat missed, retrying')
                break

while attempts = 3:
  #create new session
  attempts == 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants