Skip to content

Bugs in SocketScience.check_recent_pings #15259

Description

@Andrew5057

The SocketScience.check_recent_pings class method has the following definition:

@classmethod
def check_recent_pings(cls):
    recent = cls._pings.sort(key=lambda p: p["timestamp"]).reverse() # 1
    if len(recent) >= 1:
        most_recent = recent[0]["timestamp"]
        now = time.time()

    if now - most_recent >= 90 or len(recent) == 0: # 2
        # No active Smokeys. Wait a random number of seconds, then switch to active.
        sleep = random.randint(0, 30)
        cls._switch_task = Tasks.later(SocketScience.switch_to_active, after=sleep)

I'm pretty sure this has two bugs on the marked lines:

  1. sort is in-place and returns None; the reversal should probably be a different line.
  2. The len check is too late to short-circuit the now check.

If there are no objections, I'm happy to fix both.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions