Bug Issue: HTTP Post requests get cancelled after 500ms


Pages: 1

ccoddes

  • Junior Stencyler
March 04, 2021, 12:18:57 am
Hello,

I'm using the HTTP POST Request block ("POST data to URL then do...") in my HTML5 game to submit scores to an external webserver. I'd like to point out a potential bug (which took me quite a while to identify) in the POST code: It seems like POST requests get cancelled after 500 ms and are unable to act on a response if the request takes longer than that time.

Background: I was wondering why my HTTP POST requests occasionally would not be able to receive a response and be in a "Stalled" status. Looking into the source (postToURL), I noticed this in the code:
Code: [Select]
var loader = new URLLoader(request);
loader.addEventListener(Event.COMPLETE, fn);

#if flash
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, defaultURLError);
loader.addEventListener(IOErrorEvent.IO_ERROR, defaultURLError);
#else
//making sure the connection closes after 0.5 secs so the game doesn't freeze
runLater(500, function(timeTask:TimedTask):Void
{
loader.close();
});
#end
   
This
Code: [Select]
runLater call was causing the issue, as my HTTP request only receives a response after 535ms which meant that the loader would be closed by then.

I managed to work around the issue by running a custom Code block that does the same as postToURL, but changing the fixed 500ms close() function to close() when an IOError event is received:

Code: [Select]

#if flash
loader.addEventListener(IOErrorEvent.NETWORK_ERROR, defaultURLError);
loader.addEventListener(IOErrorEvent.IO_ERROR, defaultURLError);
#else

var onError = function(event:IOErrorEvent):Void {
loader.close();
trace("Could not POST to URL. Error: " + event.text);
};

loader.addEventListener(IOErrorEvent.IO_ERROR, onError);

I'm not sure of the reason for the 500ms URLLoader close() call, but I found a discussion on the forums which looked like it was to address a different problem (visitURL freeze) http://community.stencyl.com/index.php/topic,35634.msg205448.html#msg205448.

Although I'm not familiar with HTTP requests and OpenFL, having a hardcoded timeout here doesn't seem very robust as it leads to "random" bugs like what I encountered, which happens when the request takes just over 500ms to complete. I'm wondering if postToURL even needs this loader.close() call (as it was meant to fix the freeze in visitURL). Or perhaps hooking it onto the IOError callback will be more reliable?


Issue updated by Justin - April 04, 2021, 06:26:36 pm
  • Tags added: 4.1.x


Pages: 1

Details

  • Reported
    March 04, 2021, 12:18:57 am
  • Updated
    April 04, 2021, 06:26:36 pm

  • View Status
    Public
  • Type
    Bug
  • Status
    New
  • Priority
    Normal
  • Version
    (none)
  • Fixed in
    (none)
  • Assigned to
    (none)
  • Category
    Engine

Tags