I have been working on updates to a project using Adobe AIR. A big focus was converting remote procedure calls (RPC) to HTTP service requests for the method of communicating with the web service. The update was going well until hitting an annoying problem that took some time to figure out. The problem was that the URLLoader would throw an IOErrorEvent for a request to the server. When debugging the .NET web service I could see that the request was reaching the point where the response is given. The error detail wasn't any use at all, "Error #2032: Stream Error.". Googling the error, some people suggested that the URL could be incorrect, but this wasn't the case for my problem because the break point was being hit in the debugging. Some advice was to add a listener for HttpStatusEvent.HTTP_STATUS and see what the status code was being returned (0), this didn't give me much to go on.

The request could be quite long running depending on the amount of data that is being returned in the response to the client. As the request was successful until I changed the parameters to increase the data returned, my first thoughts was that it could be a timeout problem. I tried the request in Chrome to see if there were any problems performing the request, but it successfully managed to receive a response. This narrowed the problem down to the client, and because the request worked when the data returned in the response was small I had a hunch it had something to do with timing out.

Some more googling and I came across a post in the Adobe forums where it mentioned that in the release of AIR 2.0 the URLRequest defaults to timing out after 30 seconds. Below is an example of how to change the default behavior and increase the timeout time.

URLRequestDefaults.idleTimeout = 1000*60*60;

The idleTimeout property on the URLRequestDefaults class accepts a duration in milliseconds. So the code above will increase the timeout to 60 minutes, which is more than enough time to fix the problem.

I probably should have solved this a lot quicker, but I just couldn't find the right result in Google, this is why I decided to write this blog post just in case another person does have the same problem.