Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault using https in multi-threaded environment #191

Open
relonger opened this issue Mar 17, 2018 · 5 comments
Open

Segmentation fault using https in multi-threaded environment #191

relonger opened this issue Mar 17, 2018 · 5 comments

Comments

@relonger
Copy link

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
@AlexDaniel
Copy link
Collaborator

I got segmentation fault even when I had no IO::Socket::SSL installed. Interesting.

@AlexDaniel
Copy link
Collaborator

AlexDaniel commented Mar 17, 2018

Not reproducible on whateverable, which is even more interesting. FWIW another simple SEGV: rakudo/rakudo#1202

@AlexDaniel
Copy link
Collaborator

AlexDaniel commented Mar 17, 2018

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).

@relonger
Copy link
Author

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;
         }
      }
   }
}

@briandfoy
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants