Bug 16112 - ObjectDisposedException at Socket_2_1.cs
Summary: ObjectDisposedException at Socket_2_1.cs
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2013-11-11 11:26 UTC by deus.verus
Modified: 2014-07-29 07:14 UTC (History)
3 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

Test case (186.68 KB, application/octet-stream)
2013-11-11 11:26 UTC, deus.verus

Description deus.verus 2013-11-11 11:26:12 UTC
Created attachment 5392 [details]
Test case

When using RabbitMQ.net factory.CreateConnection() to connect to a valid host with the broker service shut down, the following exception is raised:

Unhandled Exception: System.ObjectDisposedException: The object was used after being disposed.
  at System.Threading.WaitHandle.CheckDisposed () [0x00016] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/corlib/System.Threading/WaitHandle.cs:434
  at System.Threading.EventWaitHandle.Set () [0x0000c] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/corlib/System.Threading/EventWaitHandle.cs:133
  at (wrapper remoting-invoke-with-check) System.Threading.EventWaitHandle:Set ()
  at System.Net.Sockets.Socket+SocketAsyncResult.set_IsCompleted (Boolean value) [0x00024] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:359
  at System.Net.Sockets.Socket+SocketAsyncResult.Complete () [0x00037] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:247
  at System.Net.Sockets.Socket+SocketAsyncResult.Complete (System.Exception e) [0x00007] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:309
  at System.Net.Sockets.Socket+Worker.Connect () [0x0018c] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:624
  at System.Net.Sockets.Socket+Worker.DispatcherCB (System.Net.Sockets.SocketAsyncResult sar) [0x00088] in /build/v2012.12/build/tmp-angstrom_v2012_12-eglibc/work/x86_64-linux/mono-native-2.11-r1/mono-2.11/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:434

I experience the error when running the attached test case and attempting to connect to another machine on the LAN which has rabbitmq broker installed but the service is shut down. I expect BrokerUnreachableException to be thrown, which is the case on windows.
The error does not occur if I try to connect to an invalid IP or localhost which does not have rabbitmq broker installed. 
About 10% of the time, BrokerUnreachableException does get thrown as expected so I suspect a timing issue or race condition.
I have seen this error on x64 Ubuntu LTS.

Trying to catch ObjectDisposedException during factory.CreateConnection() doesn't seem to work - the application crashes regardless. I'd really appreciate a suggestion how this can be detected and caught without crashing the application. 

Mono JIT compiler version 2.11 (tarball Fri Jul 19 11:44:26 CEST 2013)
Copyright (C) 2002-2011 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       normal
        Notifications: epoll
        Architecture:  armel,soft-float
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)

Note You need to log in before you can comment on or make changes to this bug.