Krambambuli has asked for the wisdom of the Perl Monks concerning the following question:
I'm searching your help while trying to overcome an issue with a script using Net::Curl::Multi in an Amazon Linux 2023 instance.
At first run, I hit the wall and get a trace likeSubsequent runs will do their job OK - for a short while. Then again a "callback function is not set"... And then again a number of runs will do OK. The script I've tried to track down the issue is here:$ ./04-curl-multi-debug.pl TRACE 1 TRACE 2 TRACE 3 TRACE 4 GET_ONE 1 GET_ONE 2 GET_ONE 3 $$self: 1 GET_ONE 4 GET_ONE 6 GET_ONE 3 $$self: 1 GET_ONE 4 callback function is not set Operation was aborted by an application callbackTRACE 6: 'Operation wa +s aborted by an application callback'
The code runs fine on an older Amazon Linux 2 instance. Any idea on how a work-around might look like? Thank you!#!/usr/bin/perl package Multi::Simple; use strict; use warnings; use Net::Curl::Multi; use base qw(Net::Curl::Multi); # make new object, preset the data sub new { my $class = shift; my $active = 0; return $class->SUPER::new( \$active ); } # add one handle and count it sub add_handle($$) { my $self = shift; my $easy = shift; $$self++; $self->SUPER::add_handle( $easy ); } # perform until some handle finishes, does all the magic needed # to make it efficient (check as soon as there is some data) # without overusing the cpu. sub get_one($) { my $self = shift; print "GET_ONE 1 \n"; if ( my @result = $self->info_read() ) { $self->remove_handle( $result[ 1 ] ); return @result; } print "GET_ONE 2 \n"; while ( $$self ) { print "GET_ONE 3 \$\$self: $$self\n"; my $t = $self->timeout; if ( $t != 0 ) { $t = 10000 if $t < 0; my ( $r, $w, $e ) = $self->fdset; select $r, $w, $e, $t / 1000; } print "GET_ONE 4 \n"; my $ret = $self->perform(); if ( $$self != $ret ) { $$self = $ret; if ( my @result = $self->info_read() ) { $self->remove_handle( $result[ 1 ] ); return @result; } print "GET_ONE 5 \n"; } print "GET_ONE 6 \n"; }; print "GET_ONE 7 \n"; return (); } 1; ############################################### ############################################### ############################################### package main; #use strict; use warnings; BEGIN { push @INC, './'; } use Data::Dumper; #use Multi::Simple; use Net::Curl qw(:constants); use Net::Curl::Easy qw(:constants); use Net::Curl::Multi qw(:constants); use Net::Curl::Share qw(:constants); #print "libcurl version: ", Net::Curl::version(), "\n"; # my $vi = Net::Curl::version_info(); # unless ( $vi->{features} & CURL_VERSION_SSL ) { # die "SSL support is required\n"; # } #print "Version Info: ", Dumper( $vi ); #use Net::Curl; #my $info = Net::Curl::version_info(); #print "libcurl version: $info->{version}\n"; #print "ares_num: $info->{ares_num}\n"; #print "features: $info->{features}\n"; #exit; sub easy { my $uri = shift; my $share = shift; #require Net::Curl::Easy qw(:constants); my $easy = Net::Curl::Easy->new( { uri => $uri, body => '' } ) +; $easy->reset; $easy->setopt( Net::Curl::Easy::CURLOPT_VERBOSE(), 1 ); $easy->setopt( Net::Curl::Easy::CURLOPT_SSL_SESSIONID_CACHE, 0 + ); $easy->setopt( Net::Curl::Easy::CURLOPT_DNS_USE_GLOBAL_CACHE, +0); $easy->setopt( Net::Curl::Easy::CURLOPT_URL(), $uri ); $easy->setopt( Net::Curl::Easy::CURLOPT_WRITEHEADER(), \$easy->{headers} ); $easy->setopt( Net::Curl::Easy::CURLOPT_FILE(), \$easy->{body} ); #$easy->setopt( Net::Curl::Easy::CURLOPT_SHARE(), $share ); # This wasn't needed prior to curl 7.67, which changed the int +erface # so that an easy that uses a cookie-share now requires an exp +licit # cookie-engine enable to use cookies. Previously the easy's u +se of # a cookie-share implicitly enabled the easy's cookie engine. #$easy->setopt( Net::Curl::Easy::CURLOPT_COOKIEFILE(), q<> ); return $easy; } my $multi; eval { $multi = Multi::Simple->new(); print "TRACE 1\n"; my $dummy = Net::Curl::Easy->new; $dummy->setopt(Net::Curl::Easy::CURLOPT_URL, 'http://example.com') +; #$dummy->setopt(Net::Curl::Easy::CURLOPT_WRITEFUNCTION, sub { retu +rn length($_[0]); }); if (not ref $dummy) { die "Cannot create easy object...?!\n"; } print "TRACE 2\n"; $multi->add_handle( $dummy ); print "TRACE 3\n"; $multi->wait(10000); print "TRACE 4\n"; my @results = $multi->get_one(); if (scalar( @results ) == 0) { die "Some ERROR occured in get_one!\n"; } my ($msg, $easy, $result) = @results; print "TRACE 5 Msg: ", Dumper( $msg ), "easy: ", Dumper( $easy ), +"Result: " , Dumper( $result ); #Net::Curl::Easy::strerror( $result ), "\n"; if ($result != Net::Curl::Easy::CURLE_OK) { my $message = Net::Curl::Easy::strerror( $result ); print "Result as string: '$message'\n"; } }; if ($@) { print "TRACE 6: '$@'"; die $@; } print "NO ERROR, all OK\n"; exit;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Net::Curl::Multi on Amazon Linux 2023 instance
by Corion (Patriarch) on Nov 20, 2024 at 20:27 UTC | |
by Krambambuli (Curate) on Nov 21, 2024 at 07:23 UTC | |
Re: Net::Curl::Multi on Amazon Linux 2023 instance
by bliako (Abbot) on Nov 21, 2024 at 11:44 UTC | |
by Krambambuli (Curate) on Nov 22, 2024 at 17:54 UTC |