HTTP Timeout not working

Other topics not directly related to Budabot (Budabot Items Extractor, AOChatProxy, etc.)
Tyrence
Posts: 1948
Joined: Sat Jan 09, 2010 1:32 am

HTTP Timeout not working

Postby Tyrence » Sun Mar 24, 2013 3:23 am

Marebone, maybe you have an idea why the timeout isn't working?

Here is a sample controller to illustrate the problem:

Code: Select all

<?php
/**
 * Authors:
 *  - Tyrence (RK2)
 *
 * @Instance
 *
 * Commands this controller contains:
 *   @DefineCommand(
 *      command     = 'delay',
 *      accessLevel = 'admin',
 *      description = "Test the bot commands",
 *      help        = 'test.txt'
 *   )
 */
class DelayController extends AutoInject {

   /**
    * Name of the module.
    * Set automatically by module loader.
    */
   public $moduleName;

   /**
    * @Setup
    */
   public function setup() {

   }
   
   /**
    * @HandlesCommand("delay")
    * @Matches("/^delay$/i")
    */
   public function delayCommand($message, $channel, $sender, $sendto, $args) {
      $url = "http://budabot.jkbff.com/test/delay.php";
      $response = $this->http->get($url)->withTimeout(2)->waitAndReturnResponse();
      print_r($response);
      $sendto->reply($response->body);
   }
}


The delay.php script it's calling is set to wait for 10s before returning "hi". In the code you can see that I have set withTimeout(2) but when I do !delay it waits the full 10s and then returns the output.
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
User avatar
Shelly
Member
Posts: 81
Joined: Wed Oct 05, 2011 1:51 am
antispam: Rimor
Location: Lost in Time
Contact:

Re: HTTP Timeout not working

Postby Shelly » Sun Mar 24, 2013 4:22 pm

Ty,

Would be my guess that it is working correctly.

It looks like it able to contact $url so there would not be a timeout occurred incident? Does the TimeOut referr to *connecting to* or the *response from* the delay.php script?

Shelly
Your type personality is: SAEK
Breakdown: Socializer 73.33%, Achiever 60.00%, Explorer 60.00%, Killer 6.67%

http://en.wikipedia.org/wiki/Bartle_Test
Tyrence
Posts: 1948
Joined: Sat Jan 09, 2010 1:32 am

Re: HTTP Timeout not working

Postby Tyrence » Sun Mar 24, 2013 8:42 pm

I think the "connecting to" delay is hardcoded to 5 seconds. And it was my understanding that the "response from" delay was the delay that was configurable.
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases
Marebone
The Team
Posts: 175
Joined: Sun Sep 04, 2011 7:38 am
antispam: Rimor

Re: HTTP Timeout not working

Postby Marebone » Mon Mar 25, 2013 7:46 am

There is only one timeout which affects both the connect and response timeout. Except if you're using https-protocol on Windows, there the connect delay is hard coded to 10 seconds, due of an unresolved bug in PHP-interpreter.

The timeout should reset whenever data has been received or send to/from the server. But, since the timeout never triggers there might be something that causes the timeout to reset constantly. Another possibility could be that there is something else preventing the eventloop within the waitAndReturnResponse() from quiting, perhaps another eventloop in callstack.
Marebone
The Team
Posts: 175
Joined: Sun Sep 04, 2011 7:38 am
antispam: Rimor

Re: HTTP Timeout not working

Postby Marebone » Mon Mar 25, 2013 7:45 pm

It would appear that the reason for this is that the SocketNotifier spams SOCKET_WRITE events at breakneck speed during the request. Each event resets the timeout timer and such prevents the timeout ever from triggering.

The correct behavior, IMO, should be that the SOCKET_WRITE event should occur only when the stream's out buffer is full (and thus nothing can be written to it) and then, on next tick, empties so that stuff can be written to it.
User avatar
Shelly
Member
Posts: 81
Joined: Wed Oct 05, 2011 1:51 am
antispam: Rimor
Location: Lost in Time
Contact:

Re: HTTP Timeout not working

Postby Shelly » Mon Mar 25, 2013 11:52 pm

Nice sleuthing you two :)

Better than my input :geek: :lol:

Shelly
I did mention I am not a professional coder... Right? ^_^
Your type personality is: SAEK
Breakdown: Socializer 73.33%, Achiever 60.00%, Explorer 60.00%, Killer 6.67%

http://en.wikipedia.org/wiki/Bartle_Test
Tyrence
Posts: 1948
Joined: Sat Jan 09, 2010 1:32 am

Re: HTTP Timeout not working

Postby Tyrence » Tue Mar 26, 2013 5:40 am

Shelly wrote:Nice sleuthing you two

Better than my input

Shelly
I did mention I am not a professional coder... Right? ^_^

You helped us get there tho. I always appreciate your input. :)
"Those who expect to reap the blessings of freedom, must, like men, undergo the fatigues of supporting it." — Thomas Paine
"Nearly all men stand adversity, but if you want to test a man's character, give him power." — Abraham Lincoln
Budabot Releases and Downloads: https://github.com/Budabot/Budabot/releases

Return to “Misc/Tools”

Who is online

Users browsing this forum: No registered users and 1 guest