poshbotio / PoshBot

Powershell-based bot framework
MIT License
536 stars 108 forks source link

PoshBot ping only occurs once #191

Closed jamesbr-ashn closed 4 years ago

jamesbr-ashn commented 4 years ago

PoshBot bot ping only occurs once

Expected Behavior

According to the inline comments, the bot backend ping should occur every five seconds.

Current Behavior

The ping occurs once after 5 seconds, but only the one time.

Possible Solution

The stopwatch is being reset, not restarted. Change the command $sw.Reset() to $sw.Restart()

A Stopwatch instance calculates and retains the cumulative elapsed time across multiple time intervals, until the instance is reset or restarted. Use Stop to stop the current interval measurement and retain the cumulative elapsed time value. Use Reset to stop any interval measurement in progress and clear the elapsed time value. Use Restart to stop current interval measurement and start a new interval measurement.

Steps to Reproduce (for bugs)

  1. Place a breakpoint on line with $sw = [System.Diagnostics.Stopwatch]::StartNew() (PoshBot.psm1, 3929)
  2. Start PoshBot
  3. When breakpoint hit, stepover the line until timer elapsed if statement
  4. Wait at least 5 seconds from timer start
  5. Stepover through if statement and back to beginning of loop
  6. Repeat step 3 and 4
  7. Stepover if statement. This time it will return to beginning of loop

Context

I was troubleshooting a connectivity issue when I found the improper implementation. This has an unknown impact. What happens to the connection if the ping is not done periodically? The ping does not appear to be logged. Should it be?

Your Environment

Name Value


PSVersion 5.1.14393.3053
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.3053
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

devblackops commented 4 years ago

Good catch @jamesbr-ashn. I'm going to merge this PR to make this behavior correct but in practice, the Ping() method isn't used in the builtin backends. The default implementation in the Backend class in an empty method and the Discord, Slack, and Teams backends either inherit the default implemention, or also provide an empty method.

If it does end up being used, it should use the correct interval though. Thanks!