locked
When trying to get the items from Healthvault in mutlthreaded environment error thrown The underlying connection was closed: Could not establish trust relationship, InnerException :The remote certificate is invalid according to the validation procedure. RRS feed

  • Question

  • Hi there,
    I am getting the above error when i try to get the items from healthvault in a multithreaded manner. First few requests will get me the data and then it starts throwing the above said error.   i wonder why should Healthvault throw this type of error when it gets same request again and again.
    I have also observed that if i try to edit a record and another thread came and tried to read it then it throws access denied exceptions.
    My appid is : 11ef65f0-0dfd-4cc7-b54c-e7acc4c22dc4
    I am trying to get details for userid: ebd75e92-557e-4e75-b8f6-49777286fe8d RecordId:a53b5075-52c4-4d87-9c90-b8f02210eb32 The folllowing is the stack trace:
     
    at Microsoft.Health.EasyWebRequest.WaitForCompletion()

     

    at Microsoft.Health.EasyWebRequest.Fetch(Uri url)

    at Microsoft.Health.EasyWebRequest.Fetch(Uri url, IEasyWebResponseHandler customHandler)

    at Microsoft.Health.HealthServiceRequest.ExecuteInternal()

    at Microsoft.Health.Web.OfflineWebApplicationConnection.ExecuteRequestWithRetry(HealthServiceRequest request)

    at Microsoft.Health.HealthServiceRequest.Execute()

    at Microsoft.Health.HealthRecordSearcher.Execute()

    at Microsoft.Health.HealthRecordSearcher.GetSingleItem(Guid itemId, HealthRecordItemSections sections)

    at Microsoft.Health.HealthRecordAccessor.GetItem(Guid itemId, HealthRecordItemSections sections)

    Thursday, February 4, 2010 12:54 PM

Answers

  • The simple answer is that a HealthVault connection object is not thread-safe, so what you are trying to do is not supported.

    You could use multiple connections.

    Thursday, February 4, 2010 3:50 PM
  • Are you sharing connection objects (say instance of OfflineWebApplicationConnection) b/w multiple threads?  For ex: Your main function creates a global connection object instance and passes it to multiple threads for them use - will NOT work.

    You need to create seperate instance of connection object for each thread seperately (say at the entry point of the thread or with some use of ThreadStatic variables).

    One way to acheive this is by : creation of the connection object and initialization should be inside the thread function's scope and dispose it off before the thread function returns. 

    Raj
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Friday, February 5, 2010 11:37 AM
  • I think it's unlikely that we would make them threadsafe. The library method level is generally not the right unit when you want to make something thread-safe - you generally want it to be threadsafe across a few calls, which can only be done at the client level.

    We have, however, thought a bit about concurrent operations. Can you explain a bit about your scenario and why you need/want to perform multiple operations at once?
    Monday, February 8, 2010 4:58 PM
  • One suggestion I have based on your post above is that if you are doing multiple atomic operations against one record (create, update, delete) , you should batch these request as against having multiple threads doing individual creates and edits.

    http://blogs.msdn.com/ericgu/archive/2008/01/18/healthvault-batching-up-queries.aspx

    You can do parallel operations against different records using a seperate threads.


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Tuesday, February 9, 2010 1:32 PM

All replies

  • The simple answer is that a HealthVault connection object is not thread-safe, so what you are trying to do is not supported.

    You could use multiple connections.

    Thursday, February 4, 2010 3:50 PM
  • Hi Eric,
    thanks a lot for the reply...
    Could you elobrate on what do you mean by multiple connections? Also i wonder if "HealthVault connection object " is not thread safe then why should it throw such weird error. I would rather expect a thread exception than that webexception.

    Is there any way i can get around this problem in offline connection? Please let me know what do you mean by using multiple connections. I tried locking the connection but still it throws the same error at times. I need to go to production ASAP and these are stress/performance bugs i am encountering at the last moment.

    Your help is highly appreciated..
    -Raj
    Friday, February 5, 2010 2:36 AM
  • Are you sharing connection objects (say instance of OfflineWebApplicationConnection) b/w multiple threads?  For ex: Your main function creates a global connection object instance and passes it to multiple threads for them use - will NOT work.

    You need to create seperate instance of connection object for each thread seperately (say at the entry point of the thread or with some use of ThreadStatic variables).

    One way to acheive this is by : creation of the connection object and initialization should be inside the thread function's scope and dispose it off before the thread function returns. 

    Raj
    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Friday, February 5, 2010 11:37 AM
  • I am not sharing instance of OfflineWebApplicationConnection b/w multiple threads. Every thread creates a new one and processes it. However i was not disposing the HealthRecordAccessor after my usage. I am marking it NULL now.I believe that will dispose the connection as well.  I don't find the Connection object to be IDisposable. So marking it null will be only the option i guess.

    I am trying few more things like using monitors and etc. This will degrade my performance but for now i will be hoping that solves my issue to some extent if not fully. If you guys have any other advice to me then please let me know.

    y d way is MS thinking to make Healthvault connection objects threadsafe in future?
    Monday, February 8, 2010 12:09 PM
  • I think it's unlikely that we would make them threadsafe. The library method level is generally not the right unit when you want to make something thread-safe - you generally want it to be threadsafe across a few calls, which can only be done at the client level.

    We have, however, thought a bit about concurrent operations. Can you explain a bit about your scenario and why you need/want to perform multiple operations at once?
    Monday, February 8, 2010 4:58 PM
  • The scenario is that i want to synchronize healthvault data with another source of data and to synchronize it i will first get the data from Healthvault and will compare with the source of data i have. If there are data mistmatch between my source of data and the HV data then i will either pull the data from Hv or push the data to HV. Since these operations have to be multiple at one go so i get those errors. 

    And on top of this if at the client side user tries to synchronize again and again then there will be many more above described operations taking place. The client is in my control so i can handle this issue...

    But when multiple operations like what i told you before starts happening.. Then Healthvault starts throwing the errors.
    Does that answer your question?
    Tuesday, February 9, 2010 7:05 AM
  • One suggestion I have based on your post above is that if you are doing multiple atomic operations against one record (create, update, delete) , you should batch these request as against having multiple threads doing individual creates and edits.

    http://blogs.msdn.com/ericgu/archive/2008/01/18/healthvault-batching-up-queries.aspx

    You can do parallel operations against different records using a seperate threads.


    Raj HealthVault Developer Tool http://xray.getrealconsulting.com
    Tuesday, February 9, 2010 1:32 PM