Using version 54.2.0.
We encountered a CurrentDomainUnhandledException, caused by an ObjectDisposedException thrown in FtpSocketStream.BeginAccept.
The problem seems to be that the connectEvent is already disposed, but the SocketAsyncEventArgs.Completed event still triggers.
We suspect this may occur, when the server doesn't create the active data connection. In our systems, we have a lot of embedded devices running a ftp server, that may power down unexpectedly (which is a normal use case for us).
This may trigger the timeout in IAsyncFtpClient.UploadStream, which then disposes the socket, which in turn triggers the Completed event with a socket error.
This event may be called in another thread, during which the ManualResetEvent can already by disposed via EndAccept()
Exceptions in this event are not observed, so result in CurrentDomainUnhandledException.
This is the stacktrace:
System.ObjectDisposedException with result 0x80131622 with message 'Cannot access a disposed object.
Object name: 'Microsoft.Win32.SafeHandles.SafeWaitHandle'.' at System.ThrowHelper.ThrowObjectDisposedException(System.Object instance) +22
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at .Interop+Kernel32.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle handle) +10
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at FluentFTP.FtpSocketStream+<>c__DisplayClass112_0.b__0(System.Object s, System.Net.Sockets.SocketAsyncEventArgs e) +0
in module FluentFTP.dll version 54.2.0+928edd5a56b237412904ce178eefc12e579d7671
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) +0
in module System.Net.Sockets.dll version 10.0.8+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) +64
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +17
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) +124
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ThreadPoolBoundHandleOverlapped.CompletionCallback(UInt32 errorCode, UInt32 numBytes, System.Threading.NativeOverlapped* nativeOverlapped) +0
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ThreadPoolTypedWorkItemQueue.System.Threading.IThreadPoolWorkItem.Execute() +80
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ThreadPoolWorkQueue.Dispatch() +227
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart() +150
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.Thread.StartCallback() +0
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
Using version 54.2.0.
We encountered a CurrentDomainUnhandledException, caused by an ObjectDisposedException thrown in FtpSocketStream.BeginAccept.
The problem seems to be that the connectEvent is already disposed, but the SocketAsyncEventArgs.Completed event still triggers.
We suspect this may occur, when the server doesn't create the active data connection. In our systems, we have a lot of embedded devices running a ftp server, that may power down unexpectedly (which is a normal use case for us).
This may trigger the timeout in IAsyncFtpClient.UploadStream, which then disposes the socket, which in turn triggers the Completed event with a socket error.
This event may be called in another thread, during which the ManualResetEvent can already by disposed via EndAccept()
Exceptions in this event are not observed, so result in CurrentDomainUnhandledException.
This is the stacktrace:
System.ObjectDisposedException with result 0x80131622 with message 'Cannot access a disposed object.
Object name: 'Microsoft.Win32.SafeHandles.SafeWaitHandle'.' at System.ThrowHelper.ThrowObjectDisposedException(System.Object instance) +22
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at .Interop+Kernel32.SetEvent(Microsoft.Win32.SafeHandles.SafeWaitHandle handle) +10
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at FluentFTP.FtpSocketStream+<>c__DisplayClass112_0.b__0(System.Object s, System.Net.Sockets.SocketAsyncEventArgs e) +0
in module FluentFTP.dll version 54.2.0+928edd5a56b237412904ce178eefc12e579d7671
at System.Net.Sockets.SocketAsyncEventArgs.OnCompleted(System.Net.Sockets.SocketAsyncEventArgs e) +0
in module System.Net.Sockets.dll version 10.0.8+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) +64
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +17
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) +124
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ThreadPoolBoundHandleOverlapped.CompletionCallback(UInt32 errorCode, UInt32 numBytes, System.Threading.NativeOverlapped* nativeOverlapped) +0
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ThreadPoolTypedWorkItemQueue.System.Threading.IThreadPoolWorkItem.Execute() +80
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.ThreadPoolWorkQueue.Dispatch() +227
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.PortableThreadPool+WorkerThread.WorkerThreadStart() +150
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca
at System.Threading.Thread.StartCallback() +0
in module System.Private.CoreLib.dll version 10.0.8-servicing.26229.119+94ea82652cdd4e0f8046b5bd5becbd11461482ca