Attached is a patch which fixes some problems we are having using
PoCoCl::UserAgent with the parallel ftp: and file: protocol handlers. Also
attached is a test script ("borrowed" liberally from the perldoc page for
PoCoCl::UserAgent) that illustrates the problem. I am soliciting input as to
the general suitability of the patch and whether I missed anything.

Versions:
---------
POE - v 0.2802
POE::Component::Client::UserAgent - v 0.05 
LWP - 5.76 
ParallelUserAgent - 2.57

Description of problem:
-----------------------
During the request initiation stage, handled in _pococ_ua_write, it is
possible for the underlying protocol handler to return a response. In cases
where the responses are non-error responses, all will be handled
appropriately. However, in cases where the returned responses are error
conditions, a couple of problems occur:
1) By not processing the error, eventually the request will time out. This
will cause an error response with return code RC_REQUEST_TIMEOUT to be
generated, thus masking the real error returned by the underlying protocol
handler.
2) If the timeout handler (_pococ_ua_timeout) is called by lack of response
processing, the process will die(). This is because the write handler,
_write_request in LWP::Parallel::UserAgent has already cleared the current
connection for the entry. When the timeout occurs, the timeout handler again
tries to clear the current connection for the entry, causing
LWP::Parallel::UserAgent to Carp::confess("No connections for '$netloc'") in
_remove_current_connection.

To replicate problem:
---------------------
Use attached test script as follows:
./test-ua FTP-URI [debuglevel]

Make sure the FTP URI points to a valid FTP server that REQUIRES
authentication, but pass either no credentials OR pass invalid ones.
Debuglevel can be turned on using level 1-9.

Example:   ./test-us ftp://baduser:[EMAIL PROTECTED]/foo.txt 9


Example output of failed run:
-----------------------------
$ ./test-ua.pl ftp://foo:[EMAIL PROTECTED]/foo.txt
Retrieving: ftp://foo:[EMAIL PROTECTED]/foo.txt
No connections for 'core-001.somecompany.com:21' at
/usr/lib/perl5/site_perl/5.8.0/LWP/Parallel/UserAgent.pm line 776
 
LWP::Parallel::UserAgent::_remove_current_connection('POE::Component::Client
::UserAgent=HASH(0xa4456cc)','LWP::Parallel::UserAgent::Entry=HASH(0xa477b34
)') called at
/usr/lib/perl5/site_perl/5.8.0/POE/Component/Client/UserAgent.pm line 300
 
POE::Component::Client::UserAgent::_pococ_ua_timeout('POE::Component::Client
::UserAgent=HASH(0xa4456cc)','POE::Session=ARRAY(0xa4480e8)','POE::Kernel=AR
RAY(0xa1a7c5c)','HASH(0xa4480a0)','timeout','POE::Session=ARRAY(0xa4480e8)',
'undef','/usr/lib/perl5/site_perl/5.8.0/POE/Component/Client/UserAgent.pm',1
24,...) called at /usr/lib/perl5/site_perl/5.8.0/POE/Session.pm line 629
 
POE::Session::_invoke_state('POE::Session=ARRAY(0xa4480e8)','POE::Session=AR
RAY(0xa4480e8)','timeout','ARRAY(0xa579aec)','/usr/lib/perl5/site_perl/5.8.0
/POE/Component/Client/UserAgent.pm',124) called at
/usr/lib/perl5/site_perl/5.8.0/POE/Kernel.pm line 843
 
POE::Kernel::_dispatch_event('POE::Kernel=ARRAY(0xa1a7c5c)','POE::Session=AR
RAY(0xa4480e8)','POE::Session=ARRAY(0xa4480e8)','timeout',512,'ARRAY(0xa579a
ec)','/usr/lib/perl5/site_perl/5.8.0/POE/Component/Client/UserAgent.pm',124,
1078776576.92054,...) called at
/usr/lib/perl5/site_perl/5.8.0/POE/Resource/Events.pm line 239
        POE::Kernel::_data_ev_dispatch_due('POE::Kernel=ARRAY(0xa1a7c5c)')
called at /usr/lib/perl5/site_perl/5.8.0/POE/Loop/Select.pm line 321
        POE::Kernel::loop_do_timeslice('POE::Kernel=ARRAY(0xa1a7c5c)')
called at /usr/lib/perl5/site_perl/5.8.0/POE/Loop/Select.pm line 329
        POE::Kernel::loop_run('POE::Kernel=ARRAY(0xa1a7c5c)') called at
/usr/lib/perl5/site_perl/5.8.0/POE/Kernel.pm line 1009
        POE::Kernel::run('POE::Kernel=ARRAY(0xa1a7c5c)') called at
./test-ua.pl line 24

Problem resolution:
-------------------
The attached patch fixes the above issue by checking for error responses in
_pococ_us_write before returning. If an error response exists, it is
forwarded on to the failure handler, on_failure.

The patch also sets the 'use_eval' flag within the UserAgent object so all
calls to the protocol handlers will be wrapped. Without this, there appears
to be no way to catch calls to die() emanating from the handlers.

Please consider this patch for inclusion in some future release of
PoCoCl::UserAgent.

Thanks,

Andy Levine
Principal Software Engineer
dynamicsoft, Inc.


Attachment: test-ua.pl
Description: Binary data

Attachment: UserAgent.pm.patch
Description: Binary data

Reply via email to