mirror of
https://github.com/pragma-/pbot.git
synced 2025-09-26 22:27:23 +02:00
Improve LagChecker
- wait until fully connected (irc.welcome) before sending PING - do not send another PING until PONG is received These changes prevent the bot from sending multiple PINGs when the ircd is heavily lagging. The multiple PINGs would queue up and then get sent all at once when the ircd unlagged, potentially causing an excess-flood disconnection.
This commit is contained in:
parent
3219c3d008
commit
f54efb0864
@ -11,7 +11,7 @@ use parent 'PBot::Core::Class';
|
||||
use PBot::Imports;
|
||||
|
||||
use Time::Duration qw/concise ago/;
|
||||
use Time::HiRes qw/gettimeofday/;
|
||||
use Time::HiRes qw/gettimeofday tv_interval/;
|
||||
|
||||
sub initialize($self, %conf) {
|
||||
$self->{pbot}->{commands}->register(sub { $self->cmd_lagcheck(@_) }, "lagcheck", 0);
|
||||
@ -20,7 +20,7 @@ sub initialize($self, %conf) {
|
||||
sub cmd_lagcheck($self, $context) {
|
||||
if (defined $self->{pbot}->{lagchecker}->{pong_received} and $self->{pbot}->{lagchecker}->{pong_received} == 0) {
|
||||
# a ping has been sent (pong_received is not undef) and no pong has been received yet
|
||||
my $elapsed = tv_interval($self->{pbot}->{lagchecker}->{ping_send_time});
|
||||
my $elapsed = tv_interval($self->{pbot}->{lagchecker}->{ping_send_time}) * 1000;
|
||||
my $lag_total = $elapsed;
|
||||
my $len = @{$self->{pbot}->{lagchecker}->{lag_history}};
|
||||
|
||||
|
@ -15,6 +15,9 @@ use Time::HiRes qw(gettimeofday tv_interval);
|
||||
use Time::Duration;
|
||||
|
||||
sub initialize($self, %conf) {
|
||||
# are we fully connected yet?
|
||||
$self->{welcomed} = 0;
|
||||
|
||||
# average of entries in lag history, in seconds
|
||||
$self->{lag_average} = undef;
|
||||
|
||||
@ -51,6 +54,9 @@ sub initialize($self, %conf) {
|
||||
|
||||
# PONG IRC handler
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.pong', sub { $self->on_pong(@_) });
|
||||
|
||||
# Don't send PING until fully connected
|
||||
$self->{pbot}->{event_dispatcher}->register_handler('irc.welcome', sub { $self->on_welcome(@_) });
|
||||
}
|
||||
|
||||
# registry trigger fires when value changes
|
||||
@ -59,7 +65,9 @@ sub trigger_lag_history_interval($self, $section, $item, $newvalue) {
|
||||
}
|
||||
|
||||
sub send_ping($self) {
|
||||
return unless defined $self->{pbot}->{conn};
|
||||
return unless defined $self->{pbot}->{conn} && $self->{pbot}->{conn}->connected && $self->{welcomed};
|
||||
|
||||
return if defined $self->{pong_received} && $self->{pong_received} == 0;
|
||||
|
||||
$self->{ping_send_time} = [gettimeofday];
|
||||
$self->{pong_received} = 0;
|
||||
@ -67,6 +75,10 @@ sub send_ping($self) {
|
||||
$self->{pbot}->{conn}->sl("PING :lagcheck");
|
||||
}
|
||||
|
||||
sub on_welcome($self, $event_type, $event) {
|
||||
$self->{welcomed} = 1;
|
||||
}
|
||||
|
||||
sub on_pong($self, $event_type, $event) {
|
||||
$self->{pong_received} = 1;
|
||||
|
||||
|
@ -25,7 +25,7 @@ use PBot::Imports;
|
||||
# These are set by the /misc/update_version script
|
||||
use constant {
|
||||
BUILD_NAME => "PBot",
|
||||
BUILD_REVISION => 4895,
|
||||
BUILD_REVISION => 4896,
|
||||
BUILD_DATE => "2025-09-25",
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user