http-useragent
http-useragent copied to clipboard
Segmentation fault using https in multi-threaded environment
use HTTP::UserAgent;
await (for 1..10 { start {
my $ua = HTTP::UserAgent.new(useragent => 'ie_w7_64', :throw-exceptions);
my $res = $ua.get("https://github.com");
#my $res = $ua.get("http://polyglot.by/");
say $res.status-line;
} })
generates:
moar(9200,0x700013399000) malloc: *** error for object 0x7fb4072eeb30: pointer being realloc'd was not allocated
*** set a breakpoint in malloc_error_break to debug
moar(9200,0x700012393000) malloc: *** error for object 0x7fb4072eebb0: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
[1] 9200 abort perl6 useragent-concurr.p6
or just:
[1] 9186 segmentation fault perl6 useragent-concurr.p6
using HTTP is fine, so problem is somewhere in IO::Socket::SSL
my versions:
perl6 -v
This is Rakudo Star version 2018.01 built on MoarVM version 2018.01
implementing Perl 6.c.
Darwin WanMini.local 17.4.0 Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64 x86_64
I got segmentation fault even when I had no IO::Socket::SSL
installed. Interesting.
Not reproducible on whateverable, which is even more interesting. FWIW another simple SEGV: https://github.com/rakudo/rakudo/issues/1202
Also, FWIW, pretty much any segfault is a rakudobug. So please submit a rakudo ticket once there's more info (e.g. caught under gdb or golfed down significantly).
Overriding get-connection, surrounding it with lock, and using my UserAgent2 instead of UserAgent seems to solve the problem.
package HTTP {
our $https_lock = Lock.new;
class UserAgent2 is HTTP::UserAgent {
multi method get-connection(HTTP::Request $request, Str $host, Int $port?) {
{
$https_lock.lock;
LEAVE $https_lock.unlock;
return callsame;
}
}
}
}
https://rt.perl.org/Public/Bug/Display.html?id=133057