Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Apr 24, 2014 at 08:16 PM by JChilton for the following reason:

Other

avatar image
0
Question by JChilton · Apr 24, 2014 at 07:35 PM · c#coroutineconnectionwebrequest

multiple webrequests, one exception causes next to time out, rest are fine

I have a coroutine of coroutines that call tasks on webrequests. However, one will (purposefully) throw a 403 exception. The very next item will then time out when it's his turn, but all the others afterwards will work just fine, and without issue.

This is really baffling to me, any insight would be appreciated.

Alternatively, if there is an easier solution to getting the HEAD of a file on a remote server, that'd be nice instead.

CLOSED: I found out the issue is that if the server does not close the connection, the client will not silently reopen it, trying to use the bad connection. Since the server sent an exception, it didn't close the feed and the next request tried using the same connection. After that one timed out, the connection was successfully closed and the whole thing ran as needed. I read that this is a .NET bug, but didn't go into it further as i solved my issue by setting request.KeepAlive to false. Albeit a bit slower, but speed was not essential in this process as it's all in the background for my user.

paraphrased code as follows:

 IEnumerator Foo(){
     string[] paths = {some list of paths};
     foreach(string s in paths){
         yield return StartCoroutine(CheckFoo(s));
     {
 }
 
 IEnumerator CheckFoo(string s){
     HttpWebRequest request = (HttpWebRequest) WebRequest.Create(s);
     request.Method = "HEAD";
     request.KeepAlive = false; // This Fixes my issue
     Task<WebResponse> task = Task.Run(() =>{
         return request.GetResponse();
     });
 
     while(!task.IsCompleted) yield return null;
     if(task.IsFaulted || task.IsCanceled){
         foreach(System.Exception e in task.Exception.InnerExceptions){
             Debug.Log(imgPath + " \n " + e);                
         }
         yield break;
     }
     HttpWebResponse response = task.Result as HttpWebResponse;
 
     foreach(string header in response.Headers.AllKeys){
         s += "\n" + header + " > ";
         s += response.Headers.Get(header);
     }
     Debug.log(s); // give me all that sweet header data
 
 }
 
 
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Coroutine not executing code after yield return <>.sendWebRequest 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Rotate an object using Quaternion.RotateTowards() inside a Coroutine? 1 Answer

How do i make sure an Object is initialized before using it ? C# 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges