Without getting into the goto issue, may I offer the code I use for tieing a session using Apache::Session::*. It is not a loop at all, therefore no chance of an infinite loop. It makes two tries at a session, once using the supplied ID (if any), and if that fails it tries a second time using undef, to get a new session. Failing that, it dies.
# $id is either a cookie-passed session ID or undef
# $sargs is a hashref of options
eval { tie %session, 'Apache::Session::Postgres', $id, $sargs };
if ($@ =~ /^Object does not exist/) { # try to get a new session
eval { tie %session, 'Apache::Session::Postgres', undef, $sargs };
die "Can't get new session: $@" if $@;
} elsif ($@) {
die "Can't get session. ID (if any): '$id' : $@";
}
cheers!