I am running into crash while using the CancelWaitForUpdates.
I see that the thread that issues this API ends up closing the socket and the other thread that is blocked on WaitForUpdate crashes with sigsegv in ssllib.
I dont understand why cancelWait thread is trying is to close the socket. Both these threads are sharing the same VimBinding and soap endpoint.
Is there set of recommended options that we need to init soap library or build vim/gsoap sdk to make this work in multi-threaded environment ?
Here is the stack trace :
@@@ Thread 2 which is issuing the CancelWaitForUpdates
gdb) t 2
[Switching to thread 2 (Thread 0x7ff602df47e0 (LWP 3069))]#0 0x0000003ee52dadbd in close () from /lib64/libc.so.6
(gdb) bt
#0 0x0000003ee52dadbd in close () from /lib64/libc.so.6
#1 0x00007ff603f9b824 in tcp_closesocket (soap=0x7ff602dcb010, fd=4) at src/stdsoap2.cpp:4546
#2 0x00007ff603f9b783 in tcp_disconnect (soap=0x7ff602dcb010) at src/stdsoap2.cpp:4531
#3 0x00007ff603f9cc93 in soap_closesock (soap=0x7ff602dcb010) at src/stdsoap2.cpp:4945
#4 0x00007ff603fbce9c in soap_try_connect_command (soap=0x7ff602dcb010, http_command=2000,
endpoint=0x444825 "https://10.10.18.10/sdk", action=0x7ff605efb7a8 "urn:vim25/5.1") at src/stdsoap2.cpp:15138
#5 0x00007ff603fbcbf3 in soap_connect_command (soap=0x7ff602dcb010, http_command=2000,
endpoints=0x444825 "https://10.10.18.10/sdk", action=0x7ff605efb7a8 "urn:vim25/5.1") at src/stdsoap2.cpp:15102
#6 0x00007ff603fbca5f in soap_connect (soap=0x7ff602dcb010, endpoint=0x444825 "https://10.10.18.10/sdk",
action=0x7ff605efb7a8 "urn:vim25/5.1") at src/stdsoap2.cpp:15070
#7 0x00007ff605d58bf8 in soap_call___ns2__CancelWaitForUpdates (soap=0x7ff602dcb010,
soap_endpoint=0x444825 "https://10.10.18.10/sdk", soap_action=0x7ff605efb7a8 "urn:vim25/5.1",
Here is the test code that tests WaitForUpdates and CancelWaitForUpdate in a loop.
main()
{
<snip ...>
// soap_init
// ssl client context init
// login
// creates prop filter etc ..
int count = 1;
while (count <= 10)
{
cout << " ##############################" << endl;
cout << " ITERATION - " << count << endl;
cout << " ##############################" << endl;
pthread_t watchUpdates;
shouldRun = true;
struct thread_data *data;
cout << " ## Launching Thread with WaitForUpdates" << endl;
int rc = pthread_create(&watchUpdates, NULL, watchForUpdates, (void*) 0);
char buffer[5];
sleep(2);
shouldRun = false;
cout << " ## Calling CancelWaitForUpdates" << endl;
ns2__CancelWaitForUpdatesRequestType CancelWaitForUpdatesRequestType;
_ns2__CancelWaitForUpdatesResponse CancelWaitForUpdatesResponse;
CancelWaitForUpdatesRequestType._USCOREthis = propColl;
if(vim.__ns2__CancelWaitForUpdates(&CancelWaitForUpdatesRequestType, &CancelWaitForUpdatesResponse) == SOAP_OK )
{
cout << "CancelWaitForUpdates - OK\n" << endl;
}
else
{
cout << "CancelWaitForUpdates - Failed\n" << endl;
soap_print_fault(vim.soap,stderr);
}
sleep(4); // Wait for thread to exit before destroying the property filter and logging out
count++;
}
<snip ..>
// destroy prop filter
// logout
// soap end/done
}
void *watchForUpdates(void *id)
{
string version("");
ns2__UpdateSet *updateSet = NULL;
int retcode = 0;
do
{
ns2__WaitForUpdatesRequestType waitForUpdateReq;
_ns2__WaitForUpdatesResponse waitForUpdateResp;
waitForUpdateReq._USCOREthis = propColl;
waitForUpdateReq.version = &version;
cout << "waiting for updates for version ==" + version + "==\n";
retcode = vim.__ns2__WaitForUpdates(&waitForUpdateReq, &waitForUpdateResp);
if(retcode == SOAP_OK)
{
updateSet = waitForUpdateResp.returnval;
cout << "The version is " + updateSet->version;
version.copy((char*)updateSet->version.c_str(), updateSet->version.size(), 0);
}
else if(retcode == -1)
{
cout << "WaitForUpdates cancelled and exited with retcode :" << retcode <<endl;
}
else
{
cout << "WaitForUpdates errored with retcode :" << retcode <<endl;
soap_print_fault(vim.soap, stderr);
}
if(updateSet)
{
cout << "Handling updates\n";
handleUpdate(updateSet);
}
}while(shouldRun);
cout << "Stopping the watchForUpdates thread\n";
}
Here it the program output ...
$ ./run.sh
RetrieveServiceContent - OK
fullName: VMware vCenter Server 5.1.0 build-756313
Login Successful: Administrator
filter creation - OK
Number of Objects 0
##############################
ITERATION - 1
##############################
## Launching Thread with WaitForUpdates
waiting for updates for version ====
## Calling CancelWaitForUpdates
WaitForUpdates cancelled and exited with retcode :-1
Stopping the watchForUpdates thread
CancelWaitForUpdates - OK
##############################
ITERATION - 2
##############################
## Launching Thread with WaitForUpdates
waiting for updates for version ====
## Calling CancelWaitForUpdates
WaitForUpdates cancelled and exited with retcode :-1
Stopping the watchForUpdates thread
CancelWaitForUpdates - OK
##############################
ITERATION - 3
##############################
## Launching Thread with WaitForUpdates
waiting for updates for version ====
## Calling CancelWaitForUpdates
WaitForUpdates cancelled and exited with retcode :-1
Stopping the watchForUpdates thread
CancelWaitForUpdates - OK
##############################
ITERATION - 4
##############################
## Launching Thread with WaitForUpdates
waiting for updates for version ====
## Calling CancelWaitForUpdates
./run.sh: line 2: 3069 Segmentation fault (core dumped)