Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
partial fix for infinite redirect bug
  • Loading branch information
lstein committed Feb 15, 2012
1 parent d501964 commit 9bec34c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 25 deletions.
9 changes: 9 additions & 0 deletions cgi-bin/gbrowse_img
Expand Up @@ -95,6 +95,15 @@ sub new {

sub run {
my $self = shift;

# work around PSGI signal munging
local *SIG = *CORE::SIG;
local $SIG{CHLD} = sub {
while ((my $kid = waitpid(-1,WNOHANG))>0) {
1;
}
};

my $render = $self->render;
$render->set_details_multiplier(1);

Expand Down
6 changes: 5 additions & 1 deletion lib/Bio/Graphics/Browser2/RegionSearch.pm
Expand Up @@ -348,7 +348,11 @@ sub search_features_locally {

# My oh my. block eval is not working as expected here. Sometimes the die is not caught.
my $status = eval <<'END';
local $SIG{ALRM} = sub { warn "alarm clock" ; die "The search timed out; try a more specific search\n"; die; };
# we set %CORE::GLOBAL::SIG here to work around PSGI signal munging
local $CORE::GLOBAL::SIG{ALRM} = sub { warn "alarm clock" ;
die "The search timed out; try a more specific search\n";
die;
};
alarm($timeout);
$result = $self->_search_features_locally(@_);
1;
Expand Down
34 changes: 17 additions & 17 deletions lib/Bio/Graphics/Browser2/Render.pm
Expand Up @@ -40,14 +40,13 @@ use constant EMPTY_IMAGE_HEIGHT => 12;
use constant MAX_SEGMENT => 1_000_000;
use constant TOO_MANY_SEGMENTS => 5_000;
use constant OVERVIEW_RATIO => 1.0;
use constant GROUP_SEPARATOR => "\x1d";
use constant LABEL_SEPARATOR => "\x1e";
use constant GROUP_SEPARATOR => "\x80";
use constant LABEL_SEPARATOR => "\x81";

my %PLUGINS; # cache initialized plugins
my $FCGI_REQUEST; # stash fastCGI request handle
my $STATE; # stash state for use by callbacks


# new() can be called with two arguments: ($data_source,$session)
# or with one argument: ($globals)
# in the latter case, it will invoke this code:
Expand Down Expand Up @@ -82,19 +81,9 @@ sub new {
$self->session($session);
$self->state($session->page_settings);
$self->set_language();
$self->set_signal_handlers();
$self;
}

sub set_signal_handlers {
my $self = shift;
$SIG{CHLD} = sub {
while ((my $kid = waitpid(-1,WNOHANG))>0) {
1;
}
};
}

sub data_source {
my $self = shift;
my $d = $self->{data_source};
Expand Down Expand Up @@ -237,14 +226,20 @@ sub run {

my $debug = $self->debug || TRACE;

# work around PSGI signal munging
local *SIG = *CORE::SIG;
local $SIG{CHLD} = sub {
while ((my $kid = waitpid(-1,WNOHANG))>0) {
1;
}
};

warn "[$$] RUN(): ",
request_method(),': ',
url(-path=>1),' ',
query_string() if $debug || TRACE_RUN;
warn "[$$] session id = ",$self->session->id if $debug;

# $self->set_source() && return;

my $session = $self->session;
my $source = $self->data_source;
if ($session->private) {
Expand All @@ -263,6 +258,7 @@ sub run {
# authentication required, but not a login session, so initiate authentication request
$self->force_authentication;
$session->flush;
$session->unlock;
return;
}
}
Expand Down Expand Up @@ -301,7 +297,8 @@ sub run {

warn "[$$] session flush" if $debug;
$self->session->flush;

$session->unlock;

delete $self->{usertracks};
warn "[$$] synchronous exit" if $debug;
}
Expand All @@ -323,12 +320,15 @@ sub set_source {

my $source = $self->session->source;

if (CGI::unescape(CGI::path_info()) ne CGI::unescape("/$source/")) {
my $request = CGI::unescape(CGI::request_uri());
my $source_str = CGI::unescape("/$source/");
if ($request !~ /$source_str/) {
my $args = CGI::query_string();
my $url = CGI::url(-absolute=>1,-path_info=>0);
$url =~ s!(gbrowse[^/]*)(?\!.*gbrowse)/.+$!$1!; # fix CGI/Apache bug
$url .= "/$source/";
$url .= "?$args" if $args && $args !~ /^source=/;
warn "redirect to $url";
print CGI::redirect($url);
return 1;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Bio/Graphics/Browser2/RenderPanels.pm
Expand Up @@ -1499,7 +1499,8 @@ sub run_local_requests {
my $oldaction;
my $time = time();
eval {
local $SIG{ALRM} = sub { warn "alarm clock"; die "timeout" };
# we set %CORE::GLOBAL::SIG here to work around PSGI signal munging
local $CORE::GLOBAL::SIG{ALRM} = sub { warn "alarm clock"; die "timeout" };
alarm($timeout);

$requests->{$label}->lock();
Expand Down
13 changes: 7 additions & 6 deletions lib/Bio/Graphics/Browser2/Session.pm
Expand Up @@ -68,7 +68,7 @@ sub new {
if (DEBUG_LOCK) {
my $state = $self->page_settings;
my @tracks = sort grep {$state->{features}{$_}{visible}} keys %{$state->{features}};
warn '[',$self->time,'] ',"[$$] READING @tracks\n";
warn '[',$self->time,'] ',"[$$] READING @tracks";
}
## DEBUG ENDS

Expand Down Expand Up @@ -127,7 +127,9 @@ sub lock {
warn '[',$self->time,'] ',"[$$] waiting on $type session lock...\n" if DEBUG_LOCK;

eval {
local $SIG{ALRM} = sub {die "timeout\n"};
# we set %CORE::GLOBAL::SIG here to work around PSGI signal munging
local $CORE::GLOBAL::SIG{ALRM} = sub {die "timeout\n";};

# timeout lock to avoid some process from keeping process open
# you may see some lock timeouts if a process is taking too long
# to release its session.
Expand All @@ -150,7 +152,7 @@ sub lock {
my $elapsed = sprintf("%5.3fs",$self->time()-$start_time);
if ($@) {
die $@ unless $@ eq "timeout\n";
warn ("[$$] session lock timed out on request after $elapsed\n",
warn ("[$$] session lock timed out on request after $elapsed. REQUEST=",
CGI::request_method(),': ',
CGI::url(-path=>1),' ',
CGI::query_string());
Expand All @@ -172,7 +174,7 @@ sub lock_flock {

mkpath($lockdir) unless -e $lockdir;
my $lockpath = File::Spec->catfile($lockdir,$lockfile);
my $o_mode = $mode eq 'exclusive' ? '>'
my $o_mode = $type eq 'exclusive' ? '>'
:-e $lockpath ? "<"
: "+>";

Expand Down Expand Up @@ -276,12 +278,11 @@ sub flush {
if (DEBUG_LOCK) {
my $state = $self->page_settings;
my @tracks = sort grep {$state->{features}{$_}{visible}} keys %{$state->{features}};
warn '[',$self->time,'] ',"[$$] WRITING @tracks\n";
warn '[',$self->time,'] ',"[$$] WRITING @tracks";
}
## DEBUG ENDS

$self->{session}->flush if $self->{session};
# $self->unlock;
warn "[$$] SESSION FLUSH ERROR: ",$self->{session}->errstr
if $self->{session}->errstr;
}
Expand Down

0 comments on commit 9bec34c

Please sign in to comment.