Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Flush logs and don't spin at 100% CPU #2

Merged
merged 2 commits into from

2 participants

@chiselwright

Hi,

I've had a few problems with log messages 'disappearing' - it looks like there's a condition where you can't connect to the server, die, log() the error after the eval{} ... but never _flush() the log handle.

As long as you keep not connecting, you keep logging but not flushing.

The first commit explicitly flushes in the error-and-log block - so that people can see something has gone wrong.

The second commit just stops the while loop going a bit crazy trying to continuously reconnect in the while(1){...} loop, needlessly pushing the CPU usage to 100%.

Hopefully these aren't insane and can be rolled into 0.16.

chiselwright added some commits
@chiselwright chiselwright Flush logs when there's an error
Sometimes we die in the eval{} *before* the call to _flush(); if this is a
connection error we never get to a point where the log information is flushed
somewhere visible
76f5422
@chiselwright chiselwright If we can't connect don't spin at 100% CPU with retries fcdb073
@pmooney pmooney merged commit 623958b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 6, 2011
  1. @chiselwright

    Flush logs when there's an error

    chiselwright authored
    Sometimes we die in the eval{} *before* the call to _flush(); if this is a
    connection error we never get to a point where the log information is flushed
    somewhere visible
  2. @chiselwright
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 3 deletions.
  1. +21 −3 lib/Catalyst/Engine/Stomp.pm
View
24 lib/Catalyst/Engine/Stomp.pm
@@ -164,6 +164,7 @@ sub run {
# munge the configuration to make it easier to write
$config->{tries_per_server} ||= 1;
+ $config->{connect_retry_delay} ||= 15;
if (! $config->{servers} ) {
$config->{servers} = [ {
hostname => (delete $config->{hostname}),
@@ -228,12 +229,29 @@ sub run {
}
};
- if ($@) {
- if ($@ eq "QUITLOOP\n") {
+ if (my $err=$@) {
+ # although it looks like a lot of pointless flush()ing we need
+ # to make sure the user(s) can see any new messages; we
+ # sometimes die before we flush() in the loop above
+
+ if ($err eq "QUITLOOP\n") {
last QUITLOOP;
}
else {
- $app->log->error(" Problem dealing with STOMP : $@");
+ $app->log->error(" Problem dealing with STOMP : $err");
+ $app->log->_flush() if $app->log->can('_flush');
+ }
+
+ # don't loop continuously if we can't connect; take a break;
+ # give the service a chance to come back
+ if ($err =~ m{Connection refused}) {
+ $app->log->info(
+ 'Unable to connect to '
+ . $template{hostname}.':'.$template{port}
+ . '; sleeping before next retry'
+ );
+ $app->log->_flush() if $app->log->can('_flush');
+ sleep $config->{connect_retry_delay};
}
}
}
Something went wrong with that request. Please try again.