[mb-commits] branch, beta, updated. Merge branch 'mbs-3535-stack-trace-hostname' into beta MBS-3535: use Sys:: Hos...

MusicBrainz Git Server <[email protected]> Tue, 29 Jan 2013 18:27:40 +0000
Newsgroups gmane.comp.audio.musicbrainz.cvs
Message-ID <E1U0FuF-00079o-Vk@wiley>
The branch, beta has been updated
       via  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=21a00690f2373171070d5e5ff189f7f1e97adca2 (commit)
       via  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=e900f14095f8a7a0e72419b4f74742b472648bd3 (commit)
      from  http://git.musicbrainz.org/gitweb/?p=musicbrainz-server/core.git;a=commit;h=84483ec73f5e18abb0d7054b31dad89627d9b701 (commit)

Summary of changes:
 Makefile.PL               |    1 +
 lib/MusicBrainz/Server.pm |    2 ++
 root/main/500.tt          |    5 +++++
 3 files changed, 8 insertions(+), 0 deletions(-)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 21a00690f2373171070d5e5ff189f7f1e97adca2
Merge: 84483ec e900f14
Author: Ian McEwen <[email protected]>
Date:   Tue Jan 29 11:37:22 2013 -0700

    Merge branch 'mbs-3535-stack-trace-hostname' into beta
    
    * mbs-3535-stack-trace-hostname:
      MBS-3535: use Sys::Hostname to print the hostname in stack traces
    
    Conflicts:
    	lib/MusicBrainz/Server.pm

diff --cc lib/MusicBrainz/Server.pm
index 18ad402,4fc8b94..5979b03
--- a/lib/MusicBrainz/Server.pm
+++ b/lib/MusicBrainz/Server.pm
@@@ -292,98 -365,10 +293,99 @@@ sub with_translations 
          use_languages => scalar @{ Translation->instance->all_languages() }
      );
  
 -    &$orig($c, @_);
 +    $code->();
  
      Translation->instance->unset_language();
 -}
 +};
 +
 +around dispatch => sub {
 +    my ($orig, $c, @args) = @_;
 +    $c->with_translations(sub {
 +        $c->$orig(@args)
 +    });
 +};
 +
 +# All warnings should be logged
 +around dispatch => sub {
 +    my ($orig, $c, @args) = @_;
 +
 +    local $SIG{__WARN__} = sub {
 +        my $warning = shift;
 +        chomp $warning;
 +        $c->log->warn($c->req->method . " " . $c->req->uri . " caused a warning: " . $warning);
 +    };
 +
 +    $c->$orig(@args);
 +};
 +
 +# Use a fresh database connection for every request, and remember to disconnect at the end
 +before dispatch => sub {
 +    shift->model('MB')->context->connector->refresh;
 +};
 +
 +after dispatch => sub {
 +    shift->model('MB')->context->connector->disconnect;
 +};
 +
 +# Timeout long running requests
 +around dispatch => sub {
 +    my ($orig, $c, @args) = @_;
 +
 +    my $max_request_time = DBDefs->DETERMINE_MAX_REQUEST_TIME($c->req);
 +
 +    if (defined($max_request_time) && $max_request_time > 0) {
 +        my $context = $c->model('MB')->context;
 +
 +        if ($context->connector->conn->connected) {
 +            $context->sql->do("SET statement_timeout = " .
 +                                  ($max_request_time * 1000));
 +        }
 +
 +        alarm($max_request_time);
 +        POSIX::sigaction(
 +            SIGALRM, POSIX::SigAction->new(sub {
 +                $c->log->error(sprintf("Request for %s took over %d seconds. Killing process",
 +                                       $c->req->uri,
 +                                       $max_request_time));
 +                $c->log->error(Devel::StackTrace->new->as_string);
 +                $c->log->_flush;
 +
 +                if (my $sth = $context->sql->sth) {
 +                    $sth->cancel;
 +                }
 +
 +                $context->connector->disconnect;
 +
 +                exit(42)
 +            }));
 +    }
 +
 +    $c->$orig(@args);
 +
 +    alarm(0);
 +};
 +
 +around 'finalize_error' => sub {
 +    my $orig = shift;
 +    my $c = shift;
 +    my @args = @_;
 +
 +    $c->with_translations(sub {
 +        $c->$orig(@args);
 +
 +        if (!$c->debug && scalar @{ $c->error }) {
 +            $c->stash->{errors} = $c->error;
 +            $c->stash->{template} = 'main/500.tt';
 +            $c->stash->{stack_trace} = $c->_stacktrace;
++            try { $c->stash->{hostname} = hostname; } catch {};
 +            $c->clear_errors;
 +            $c->res->{body} = 'clear';
 +            $c->view('Default')->process($c);
 +            $c->res->{body} = encode('utf-8', $c->res->{body});
 +        }
 +    });
 +};
 +
  =head1 NAME
  
  MusicBrainz::Server - Catalyst-based MusicBrainz server

commit e900f14095f8a7a0e72419b4f74742b472648bd3
Author: Ian McEwen <[email protected]>
Date:   Sat Jan 26 13:47:20 2013 -0700

    MBS-3535: use Sys::Hostname to print the hostname in stack traces

diff --git a/Makefile.PL b/Makefile.PL
index 08c20c3..a9ce06f 100644
--- a/Makefile.PL
+++ b/Makefile.PL
@@ -86,6 +86,7 @@ requires 'Statistics::Basic'                          => '1.6602';
 requires 'String::CamelCase';
 requires 'String::ShellQuote'                         => '1.030';
 requires 'String::TT'                                 => '0.03';
+requires 'Sys::Hostname';
 requires 'Template::Plugin::Math';
 requires 'Template::Plugin::Class';
 requires 'Template::Plugin::JavaScript';
diff --git a/lib/MusicBrainz/Server.pm b/lib/MusicBrainz/Server.pm
index ac69ca7..4fc8b94 100644
--- a/lib/MusicBrainz/Server.pm
+++ b/lib/MusicBrainz/Server.pm
@@ -11,6 +11,7 @@ use MusicBrainz::Server::Log qw( logger );
 use aliased 'MusicBrainz::Server::Translation';
 
 use Try::Tiny;
+use Sys::Hostname;
 
 # Set flags and add plugins for the application
 #
@@ -328,6 +329,7 @@ around 'finalize_error' => sub {
             $c->stash->{errors} = $c->error;
             $c->stash->{template} = 'main/500.tt';
             $c->stash->{stack_trace} = $c->_stacktrace;
+            try { $c->stash->{hostname} = hostname; } catch {};
             $c->clear_errors;
             $c->res->{body} = 'clear';
             $c->view('Default')->process($c);
diff --git a/root/main/500.tt b/root/main/500.tt
index abeebf6..a616a56 100644
--- a/root/main/500.tt
+++ b/root/main/500.tt
@@ -42,6 +42,11 @@
             [% END %]
         </p>
         [% END %]
+        [% IF hostname %]
+        <p>
+            <strong>[% l('Host:') %]</strong> [% hostname %]
+        </p>
+        [% END %]
         [% IF use_languages %]
         <p>
             <strong>[% l('Interface language:') %]</strong> [% current_language %]

-----------------------------------------------------------------------


hooks/post-receive
-- 
mb_server