/*
Minimal scripy for reproducing the error

needed languages

LANGUAGE plpgsql
LANGUAGE plperlu
Perl module: LWP::UserAgent
Perl v5.10.0
LWP::UserAgent v5.813

NB! crash happens only with HTTPS: protocol
*/

CREATE TABLE crashtest
(
  id integer,
  val varchar
);

INSERT INTO crashtest (id, val) VALUES (1, '');

CREATE OR REPLACE FUNCTION crashtest()
  RETURNS character varying AS
$BODY$
begin
perform crashtest_request();
update crashtest set val = 'XXX' where id=1;
perform pg_sleep(2);
RETURN 'OK';
END;
$BODY$
  LANGUAGE plpgsql VOLATILE SECURITY DEFINER;

CREATE OR REPLACE FUNCTION crashtest_request()
  RETURNS text AS
$BODY$
use strict;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'https://encrypted.google.com/'); 
# my $req = HTTP::Request->new(GET => 'https://www.paypal.com/ee/'); 
my $res = $ua->request($req);
return 'OK';
$BODY$
  LANGUAGE plperlu VOLATILE;

/*
-- now, run in at least psql 2 connectios simultaneously
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
*/


