Skip to content
This repository has been archived by the owner on Dec 9, 2021. It is now read-only.

Session.Create in WebApplication hangs #3

Closed
ddNils opened this issue Aug 4, 2017 · 14 comments
Closed

Session.Create in WebApplication hangs #3

ddNils opened this issue Aug 4, 2017 · 14 comments
Assignees

Comments

@ddNils
Copy link

ddNils commented Aug 4, 2017

Hi there, I got the sample working, but when I try to move/copy the code to my Web-Application, where I want to use it, it just hangs on char[] sessionId = session.Create();
Checking with fiddler, it did send a request to vCenter and got a response including a secret, but the function never returns. Any idea how to solve this?

@ddNils
Copy link
Author

ddNils commented Aug 7, 2017

I made a demo - project.

  1. Update Reference to SamplesCommon Project
  2. In Test.axps.cs - insert your vCenter url and credentials.

TestVmApi.zip

@godefroi
Copy link

godefroi commented Nov 6, 2017

I've also seen this behavior in session.Create(). It seems like the API just hangs whenever there's an error.

@vinpai
Copy link
Contributor

vinpai commented Jan 30, 2018

This might be an issue in your app. Please troubleshoot your problem to resolve this issue. There are samples you can refer to, to understand how to create a user session in the sources of the repository. If needed, you may take help from the community forums here - https://code.vmware.com/forums/7504/vsphere-automation-sdk-for-.net

@vinpai vinpai closed this as completed Jan 30, 2018
@godefroi
Copy link

@vinpai I couldn't imagine a less helpful response than yours. You have done a disservice to the community, and if you're an employee of VMware, you've badly represented them to the community.

@vinpai
Copy link
Contributor

vinpai commented Jan 30, 2018

Unfortunately, I am not allowed to open zip files in the corporate network. If you can post your code to some repository somewhere, then I can take a look at your code and check if you are missing something. Would you be able to do that ?

@vinpai
Copy link
Contributor

vinpai commented Jan 31, 2018

Ok, I wrote a quick webapp sample here which lists vms - https://github.com/vmware/vsphere-automation-sdk-.net/tree/master/vmware/samples/vcenter/vm/list/ListVMsWebApp

Hope that helps resolve your issue.

@strefethen
Copy link

@ddNils & @godefroi Does the above sample help resolve the issues you were seeing?

@ddNils
Copy link
Author

ddNils commented Feb 14, 2018

Yes it does. It works for me. Though I am not sure how.

@ddNils
Copy link
Author

ddNils commented Feb 14, 2018

I did some additional analysis. It seems the async methods for both LoginByUsernameAndPasswordAsync and ListAsync() are working.
The synchronous Methods however do not work for me. In ASP.Net Async Pages are not the default (they have to explicitly marked as async through Async="true") so usually I try to use the synchronous methods.

Thank you very much for the troubleshooting and provided solution @strefethen and @vinpai . I wish the synchronous methods would work better or at least drop better errors. The added sample will probably help in the future.

@vinpai
Copy link
Contributor

vinpai commented Feb 14, 2018

I think ASP .NET goes into a deadlock when you use synchronous methods or block on an async method. So, you have to use async all the way. You won't see any errors because your code is deadlocked. There are some blog posts on msdn about this - https://msdn.microsoft.com/en-us/magazine/jj991977.aspx

@strefethen
Copy link

strefethen commented Feb 14, 2018

@ddNils as Vinod points out I'd be pretty careful using sync methods server side as that's a pretty easy way to bring down your server or at least tie it up so you quickly max out connections.

Glad the example helped.

@godefroi
Copy link

I think it's pretty irresponsible to say "it's not safe to use synchronous methods in a server-side context". For most of the history of server-side contexts, synchronous methods were all that were available. If the async methods work, that's fantastic, but if the synchronous ones don't, then that's a bug in the SDK.

@strefethen
Copy link

@godefroi hmm, not really sure where that quote is from. Anyhoo, for those following along I'll leave you with Microsoft's advice and suggestions for avoiding "performance devastation" using synchronous server-side web requests.

https://msdn.microsoft.com/en-us/library/aa480507.aspx

Regards

@maurizio1976
Copy link

maurizio1976 commented Jan 27, 2020

Hi
If this can help, I have verified using the VMware vSphere Automation SDKs that:

  • If I use the example "ListVMsWebApp" of the VMWARE SDK , LoginByUsernameAndPasswordAsync" function works correctly
  • If I use the example "EthernetConfiguration" of the VMWARE SDK,"LoginByUsernameAndPassword" function works correctly

If I try to use both examples, in order to have a list of Virtual machines and then launch a VM stop command, reusing the exact same code, the execution just hangs on char[] sessionId = session.Create();
(as it happens for the user "ddNils")

I have verified from the vmware logs (/storage/log/vmware/vpxd/vpxd.log)
that I have the following error:

LoginByToken failed: Connection refused: The remote service is not running,
OR is overloaded, OR a firewall is rejecting connections.

I was unable to find a solution... I also tried to use only synchronous connections,if anyone could help me....

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants