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 ()
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)

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

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report for Bug 16112 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:

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)