OlegG has asked for the wisdom of the Perl Monks concerning the following question:

Is there a way to specify Net::Telnet timeout with WWW::Mechanize::Firefox? At the moment my internet connection is very slow and sometimes I get error with $mech->get():
command timed-out at /usr/local/share/perl/5.10.1/MozRepl/Client.pm line 186
  • Comment on WWW::Mechanize::Firefox and Net::Telnet timeout

Replies are listed 'Best First'.
Re: WWW::Mechanize::Firefox and Net::Telnet timeout
by Corion (Patriarch) on Apr 27, 2011 at 13:38 UTC

    I think there is no straight way to pass a longer timeout to the Net::Telnet instance. As a workaround, you can reach deep into the nested objects:

    $mech->repl->repl->timeout(100000);

    But I wonder - WWW::Mechanize::Firefox polls for results from Firefox, so there should be no timeout even if a website is slow to respond. The main cause I know for getting timeout errors is when I send invalid Javascript code over to Firefox.

      $mech->repl->repl->timeout(100000);
      Unfortunatly it does not work:
      Can't locate object method "timeout" via package "MozRepl"

      Documentation says this should:
      $mech->repl->repl->setup_client( { extra_client_args => { timeout => 1 +80 } } );

      But after this statement $mech->get() raises an error:
      MozRepl::RemoteObject: TypeError: repl.breakLink is not a function
      But I wonder - WWW::Mechanize::Firefox polls for results from Firefox, so there should be no timeout even if a website is slow to respond. The main cause I know for getting timeout errors is when I send invalid Javascript code over to Firefox.
      Last commands before timeout which I can see with strace:
      write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 999993} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\n", 4096) = 38 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 964561} +) read(3, "repl> ", 4096) = 6 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997753} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997763} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999992 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 998085} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999992 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997690} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\n", 4096) = 38 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 960641} +) read(3, "repl> ", 4096) = 6 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999992 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997790} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997765} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997764} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997768} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999992 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 999993} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997789} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999992 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 996842} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\nrepl> ", 4096) + = 44 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 997698} +) read(3, "\"{\"result\":{\"result\":0,\"type\":null}}\"\n", 4096) = 38 select(8, [3], NULL, NULL, {11, 0}) = 1 (in [3], left {10, 960724} +) read(3, "repl> ", 4096) = 6 select(8, NULL, [3], NULL, {11, 0}) = 1 (out [3], left {10, 999993 +}) write(3, "JSON.stringify( function(){ var res = repl.getAttr(17,\"busy +\")\n; return { result: res }}())\n", 91) = 91 select(8, [3], NULL, NULL, {11, 0}) = 0 (Timeout) write(2, "command timed-out at /usr/local/share/perl/5.10.1/MozRepl/Cl +ient.pm line 186\n", 77) = 77

        This is weird and I don't know where that timeout comes from. Maybe it really is Firefox timing out as it is busy synchronously fetching some result. As you see in the trace, WWW::Mechanize::Firefox polls every second (or so) to see whether Firefox has fetched a page.

        If it really is Net::Telnet, then you'll have to dive down:

        $mech->repl->repl->client->{telnet}->timeout($new_timeout);