FTP hangs when releasing interface

Every now and then when I call the Release function on the library it hangs and does not return. The ftp log does not give any hint:

[20051215 15:25:06] SmartFTP FTP Library v1.5.7.5
[20051215 15:25:06] Resolving host name "169.254.109.212"
[20051215 15:25:06] Connecting to 169.254.109.212 Port: 21
[20051215 15:25:06] Connected to 169.254.109.212.
[20051215 15:25:06] 220 Service ready for new user.
[20051215 15:25:06] USER bssaudio
[20051215 15:25:06] 331 User name okay, need password.
[20051215 15:25:06] PASS trousers
[20051215 15:25:07] 230 User logged in, proceed.
[20051215 15:25:07] SYST
[20051215 15:25:07] 215 BSS system type.
[20051215 15:25:07] FEAT
[20051215 15:25:07] 500 Syntax error, command unrecognized.
[20051215 15:25:07] TYPE I
[20051215 15:25:07] 200 Command okay.
[20051215 15:25:07] REST 0
[20051215 15:25:07] 550 Requested action not taken.
[20051215 15:25:07] PWD
[20051215 15:25:07] 257 "/" is Current Directory
[20051215 15:25:07] PORT 169,254,59,100,166,109
[20051215 15:25:07] 200 Command okay.
[20051215 15:25:07] RETR dfp.dfh
[20051215 15:25:07] 150 File status okay; about to open data connection.
[20051215 15:25:07] 89 bytes transferred. (1.37 KB/s) (63 ms)
[20051215 15:25:07] 226 Closing data connection.
[20051215 15:25:07] PORT 169,254,59,100,166,111
[20051215 15:25:07] 200 Command okay.
[20051215 15:25:07] RETR 00000000.dfp
[20051215 15:25:07] 150 File status okay; about to open data connection.
[20051215 15:25:07] 64564 bytes transferred. (212 KB/s) (297 ms)
[20051215 15:25:07] 226 Closing data connection.
[20051215 15:25:07] QUIT
[20051215 15:25:07] 221 Service closing control connection.
[20051215 15:25:07] Client closed the connection.

My initialisation and destruction code is as follows:

CFTPClient::CFTPClient ()

{

	m_bInitialised = FALSE;



	// init COM for this thread

	::CoInitialize(NULL);



	try

	{



		sfFTPLib::IGlobalPtr pGlobal;

		if(SUCCEEDED(pGlobal.CreateInstance(__uuidof(sfFTPLib::Global))))

		{

			// Load the licence file into the DLL

			if (pGlobal->LoadLicenseKeyData(_szLicence))

			{

				HRESULT hr = m_ftp.CreateInstance(__uuidof(sfFTPLib::FTPConnectionMTA));

				if (SUCCEEDED(hr))

				{

					m_bInitialised = TRUE;



					if (nGetRegistryInt (REG_SECTION_GENERAL, _T("LogFTP"), FALSE, FALSE))

					{

						// Use log file

						m_ftp->LogFile = _T("C:\\FTPLOG.TXT");

					}



					// Set timeout

					m_ftp->Timeout = nGetRegistryInt (REG_SECTION_GENERAL, _T("FTPTimeout"), 30, FALSE);// 30 second timeout

				}

			}

			else

			{

				AfxMessageBox(_T("Failed to load FTP license key data."), MB_ICONERROR);

			}

		}

	}

	catch (_com_error& ce)

	{

		dump_com_error (ce);

	}

	

	ASSERT (m_bInitialised);

}



CFTPClient::~CFTPClient ()

{

	if (m_ftp)

	{

		// Release ftp client

		m_ftp.Release (); // This is the function call which hange

	}



	::CoUninitialize ();

}

Here is the stack if that is any use

 	ntdll.dll!7c90eb94() 	

 	ntdll.dll!7c90e9ab() 	

 	kernel32.dll!7c8094f2() 	

 	user32.dll!77d48832() 	

 	user32.dll!77d487ff() 	

 	kernel32.dll!7c8399f3() 	

 	user32.dll!77d4bbfe() 	

 	user32.dll!77d49278() 	

 	user32.dll!77d4bcad() 	

 	sfFTPLib.dll!11978724() 	

 	sfFTPLib.dll!11978a15() 	

 	sfFTPLib.dll!11946b3f() 	

 	sfFTPLib.dll!119537f8() 	

 	sfFTPLib.dll!11953858() 	

 	sfFTPLib.dll!1195370e() 	

 	Roadrunner.exe!_com_ptr_t<_com_IIID<sfFTPLib::IFTPConnection,&_GUID_65d75061_6343_4124_9d64_64f1eabb34c2> >::Release()  Line 582 + 0x12	C++

>	Roadrunner.exe!CFTPClient::~CFTPClient()  Line 136	C++

Any ideas on why this is happening?

Hi ..

It looks like a multi thread problem.
Try to use ::CoInitializeEx(0, COINIT_MULTITHREADED) instead of ::CoInitialize().
Do you use the library in Async mode or not?
Do you register to any events? If yes, did you revoke it before calling the Release function?
Is the deconstructor called from another thread while another method of the IFTPConnectionMTA interface is in progress?
-Mat

I have also noticed that when it is stuck in this call, my main application has a message loop running. Could it be something to do with the "UseMessageLoop" member in the FTP connection class? I have tried forcing that to FALSE.

It may also be worth mentioning, that I do see a thread exit in my trace output when I call Release.

Graham

Try to call Abort() and then Close() which is not documented before you call Release.

In our code it would look like this:

if (m_pFTP)
{
m_pFTP->Abort();
m_pFTP->Close();

// also sets the interface pointer to NULL
m_pFTP.Release();

if (m_pDispEvent)
{
m_pDispEvent->Revoke();
m_pDispEvent->Release();
m_pDispEvent = NULL;

bRet = true;
}
}

-Mat

Still hangs in the Release function.

Do you have the problem in the Release and Debug build?

-Mat

It happens in both release and debug. It seems to happen more frequently in debug however, which would suggest a timing issue.

I do not have any other ideas at the moment. But if you want I can provide you a debug build of the library including the PDB files. If you are interested please send an email to any of our email addresses and request it.
Thanks
-Mat


I do not have any other ideas at the moment. But if you want I can provide you a debug build of the library including the PDB files. If you are interested please send an email to any of our email addresses and request it.
Thanks
-Mat

I have sent an e-mail to your sales e-mail address. I tried to PM you but it said your inbox was full.

Thanks.