-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vpshere connection connect.SmartConnect does not persist for longer than 15 min inactive time. #347
Comments
@tianhao64 Could you please help. |
i want to know too. but nobody help.. |
@vmware/pyvmomi-maintainers any chance of you guys taking a look at this? |
Looks like the CONNECTION_POOL_IDLE_TIMEOUT_SEC is set to 900 secs in SoapAdapter.py. However, Connect/SmartConnect doesn't take the timeout parameter so the default is always used. One quick workaround can be changing the default timeout to a larger number or even disabled it by setting to -1: https://github.com/vmware/pyvmomi/blob/master/pyVmomi/SoapAdapter.py#L56 |
I can confirm that raising the timeout fixes the issue. Would it be possible to implement something so that the timeout is configurable from a public method somewhere? If I can find the time, I will try to make a PR. |
@svdgraaf thanks! |
Has there been any update on getting a fix for this issue? |
Faced the same issue when started working on interactive cli tool for VM management, |
Hi team, |
Anyone can help to make the change? We need to add the CONNECTION_POOL_IDLE_TIMEOUT_SEC parameter to SmartConnect and pass the value all the way to SoapStubAdapter. |
I have added the parameter 'connectionPoolTimeout' in both SmartConnect and SmartConnectNoSSL. This problem is I cannot push my branch up to the repo. @tianhao64 |
@magianxd Thanks for the change. Can you create a pull request? I will merge the change if everything looks good. |
@tianhao64, I cannot create a new branch. Push returns 403 error. |
@magianxd Can you fork the repo, push the change to your own repo and create a pull request? |
looks good. Thanks @magianxd @tianhao64 |
@tianhao64, there is still a bug in the code. connectionPoolTimeout is not passed to __RetrieveContent in __Login, I'm forking a new repo and submitting a PR |
File "C:\Users\xiaos3\PycharmProjects\pyvmomi\pyVmomi\VmomiSupport.py", line 574, in call @tianhao64, when I use the master branch code (PR #493 inlcuded) in my local development environment, the code encountered the above issue. Do you have any ideas? This issue occurs when accessing pyvmomi objects |
@magianxd can you share your code? |
@tianhao64 I might find the root cause of this not authenticated issue. The connection timeout value, which is 900s, is not the root cause. The code will close idle connections after 900s. If there are no connections in the connection pool available, the code will create a new connection to send requests. Which means the code will always get response from vCenter. Another point is that I still meet the Not Authenticated issue after PR #493 merged. The root cause to Not Authentication issue should be too many sessions to vCenter. User should not use SmartConnect to get service instance each time. They should get service instance only once and check if the current session is timeout. If current session becomes inactive, logout and re-login. So, the PR #493 should be rolled back since it will cause the connection closed unexpectedly issue. Or you can review a fix that I have made for this issue. Will let you know when PR is created |
@magianxd You are right, It looks like the connectionPooltimeout parameter only close idle connections from the client side, and if the client connection was idle longer than the timeout value, a new connection will be created automatically. How many connections you created using SmartConnect? I suspect your timeout issue is due to the server close the connection because the session times out. This is controlled on server side and is configurable via server settings. See https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004663. Another option is to try SessionOrientedStub which will re-login if the previous session times out. I think PR #493 was valid. We just add the support to pass the customized connectionPooltimeout to SoapStubAdapter. Do you see any issues with it? |
@tianhao64. The issue is that if users pass negative numbers for connectionPoolTimeout, _CloseIdleConnections will not close any connection and all the requests sent to vCenter will use the initial connection. When the initial connection become invalid, the code will fail. I have added an else clause to force the code remove old connections when connectionPoolTimeout is set to negative numbers. |
@tianhao64 Do you have any example of using SessionOrientedStub. BTW, Can I configure vCenter to never timeout? |
There is an example documented in the code: pyvmomi/pyVmomi/SoapAdapter.py Line 1530 in 912e365
|
@magianxd I don't think you can make vcenter never timeout. Also it's probably not a good idea to do so. |
@tianhao64 Thanks. Do you mind if I add an argument named 'relogin' in SmartConnect and SmartConnectNoSSL to enable automatic re-login? |
@magianxd Adding a keep-alive capability is probably better than re-login. re-login means we need to somehow cache the password and that might be considered as a security risk... |
Here is the right KB article on how to increase the server session timeout: https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2004663 |
Hi, -never close the connection to vsphere until i use Disconnect(conn)i.e after 2 hrs i am trying to display vm details ,facing below error [2017-04-25 15:31:31,135] ERROR in app: Exception on /vmlists [GET] it is small application when ever user logout that time only session logout will happen.(connection may be idle 2 or 5 or couple of hrs) can anyone suggest how to solve this |
@AnushaY1 Passing connectionPoolTimeout = -1 won't change session timeout. -1 only means client will never close a idle connection, it doesn't mean the connection will be valid forever. A soap request session will be timeout after 30min on server side, regardless whether or not the client closes the connection. Session timeout is a common security best practice. Change the session timeout or workaround it can introduce security risk. That said, if increasing the session timeout is really needed in script, you have two options:
Hope it helps! |
Here is a solution to resolve session timeout issue.
|
working.thanks |
@magianxd hello, if this way can keep session alive? what does it mean set CONNECTION_POOL_IDLE_TIMEOUT_SEC=0? |
This will allow, among other things, to control connectionPoolTimeout (vmware/pyvmomi#491) and prevent timeout for automation execution and other long operation, while maintaining active connection for periods that are longer than 15 minutes. See discussion: vmware/pyvmomi#347
…ption in case of idle timeouts. This is according to solution specified here: vmware/pyvmomi#347
…ption in case of idle timeouts. This is according to solution specified here: vmware/pyvmomi#347
* develop: Add SmartStubAdapter support to avoid vim.fault.NotAuthenticated exception in case of idle timeouts. This is according to solution specified here: vmware/pyvmomi#347 TRIVIAL Fix missing comma TRIVIAL Move protocol and port params to the end of the kwargs TRIVIAL Expose protocol and port parameters buildout.cfg: changed isolated python version to v3.8.0.2
@tianhao64 , @hartsock
This issue is an offshoot of Issue #194 and #294 -----
My environment consists of a SAN attached to ESX host.
I am currently using pyvmomi 6.0 with Python 2.7.10 -
This is how am trying to connect to the vsphere web client (As per #294,)
the Test does below -
I am consistently hitting failure in Step 5 , while trying to power off the first Vm. Typical stack trace looks like this -
File "/home/usr/banalas/139895/testSW/lib/ClientHostVMware.py", line 682, in vmPowerOff
dlog.debug("Powering off " + virtualMachine.name)
File "/home/usr/banalas/139895/testSW/lib/pyVmomi/VmomiSupport.py", line 560, in call
return self.f(args, *kwargs)
File "/home/usr/banalas/139895/testSW/lib/pyVmomi/VmomiSupport.py", line 383, in _InvokeAccessor
return self._stub.InvokeAccessor(self, info)
File "/home/usr/banalas/139895/testSW/lib/pyVmomi/StubAdapterAccessorImpl.py", line 47, in InvokeAccessor
raise objectContent.missingSet[0].fault
vim.fault.NotAuthenticated: (vim.fault.NotAuthenticated) {
dynamicType = ,
dynamicProperty = (vmodl.DynamicProperty) [],
msg = '',
faultCause = ,
faultMessage = (vmodl.LocalizableMessage) [],
object = 'vim.VirtualMachine:vm-1050',
privilegeId = 'System.View'
I ve also seen pyvmomi/SoapAdapter.py having CONNECTION_POOL_IDLE_TIMEOUT_SEC =900 secs which is 15 mins.
Is this the reason for my consistent failure? Can I try using a new connection to the vsphere before the power off task? How do I ensure the vsphere connection instance can be tolerant of idle timeouts > 15 mins and not hit vim.fault.NotAuthenticated.
Please suggest how to resolve this issue.
The text was updated successfully, but these errors were encountered: