Windows 2003 -- RasHangUp blocks for several seconds before returning, and handle count keeps climbing?

I am using RAS to create and disconnect VPN connections.  I can establish the connection without any problems and transfer data across it.  However, I am experiencing two issues:

1.  RasDial blocks for about 5 seconds before returning.
2.  According to Task Manager, the program's handle count is steadily increasing, even though I am careful to give RAS enough time to release the handle.


Here is my hangup code, :

int hangup(HRASCONN* vpnConn)
   {

   DWORD RASDialStatus = -1;
   RASCONNSTATUS vpnConnStatus;

   memset ((void*) &vpnConnStatus, 0, sizeof(RASCONNSTATUS));
   vpnConnStatus.dwSize = sizeof(RASCONNSTATUS);

   RASDialStatus = RasHangUp(*vpnConn);
   

   if (!RASDialStatus)
      {
      while (RASDialStatus != ERROR_INVALID_HANDLE)
         {
         RASDialStatus = RasGetConnectStatus (*vpnConn, &vpnConnStatus);
         Sleep(0);
         }
      }

   /* Error handling stuff goes here */

   }


I thought at first that the while() loop was causing the delay.  However, when I step through the code, RasHangup() blocks for about 5 seconds before it returns 0.  The while loop runs just once before the RasGetConnectStatus returns ERROR_INVALID_HANDLE.

Does anyone know what might be causing RasHangup to take so long to return?  Could it be something in the way that I am initializing the connection properties when I call RasDial?

Thanks!
LVL 1
TomProAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grg99Commented:
I would not worry about the delay.   If it's troublesome you could always run that  code in a separate thread.

0
TomProAuthor Commented:
Unfortunately, the delay *is* an issue.  The program depends on retrieving data over VPN connections as quickly as possible.  It's important to have the user wait as little as possible as the program makes up to 20 consecutive VPN connections to locate information.  

Even cutting the delay down from 5 seconds to 3 seconds per connection could make considerable difference for our end users.
0
TomProAuthor Commented:
Does anyone have any additional insight on this issue?

Thanks!
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

grg99Commented:
You could spin off each connection as a separate thread, unless there is some concurrency issue.   With a little luck you could have everything happening in parallel instead of serially.



0
TomProAuthor Commented:
grg99, this approach is a good idea except for one problem:  the IP address that I access once I open the VPN is the same for each VPN connection.  

In other words, if I have VPN firewalls with external addresses a.a.a.a, b.b.b.b, and c.c.c.c, once I connect to each, my program interacts with a system at address e.e.e.e behind the VPN.

Also, I am still searching for an answer to why I am seeing an increase in handle count each time the posted code runs.

Thanks guys!
0
TomProAuthor Commented:
Update regarding this issue -- I have since switched to a different network connection strategy that avoids VPN, so I was unable to find a true fix for this problem.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.