/*
Minimaalne komplekt vea reprodutseerimiseks:
Postgre andmebaas
LANGUAGE plpgsql
LANGUAGE plperlu
Perli moodul: LWP::UserAgent
Perl v5.10.0
LWP::UserAgent v5.813

Crashi reprodutseerimiseks tuleb kasutada HTTPS päringu.
*/

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://www.eesti.ee/est/'); # Peab olema https ! 
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;

/*
-- Vähemalt kahes SQL aknas tuleb paralleelselt käivitada:
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
select crashtest();
*/


