Protocols.HTTP.Query doesn't always remove timeout callback properly
Imported from http://bugzilla.roxen.com/bugzilla/show_bug.cgi?id=4773
Reported by Tobias Liin liin@roxen.com
When using Protocols.HTTP.Query()->timed_async_fetch() both the ok callback and the fail callback will be called, after a successful fetch.
### example: ###
object o;
int main() {
o = Protocols.HTTP.Query();
o->data_timeout = 4;
o->set_callbacks(req_ok, req_fail);
o->async_request("www.roxen.com", 80, "GET /index.xml HTTP/1.0");
return -1;
}
void req_ok() {
werror("req_ok(): %O\n", o);
o->timed_async_fetch(data_ok, data_fail);
}
void req_fail() {
werror("req_fail: %O()\n", o);
}
void data_ok() {
werror("data_ok: %O()\n", o);
}
void data_fail() {
werror("data_fail: %O()\n", o);
}
###############
The following patch for Query.pike v1.101 will fix it (I don't know if its the best way though):
@@ -376,6 +376,7 @@
if (!zero_type (headers["content-length"]) &&
sizeof(buf)-datapos>=(int)headers["content-length"])
{
+ remove_call_out(async_timeout);
con->set_nonblocking(0,0,0);
request_ok(@extra_args);
}
It adds remove_call_out(async_timeout); in async_fetch_read() in the case of all data having been received.