Xamarin-macios: Application crashes on shutdown if you still have observers running

Created on 15 Apr 2019  路  6Comments  路  Source: xamarin/xamarin-macios

Steps to Reproduce

  1. Create a Xamarin.Mac app that attaches observers
  2. Do not dispose the observers
  3. Observe that the finalizer runs after the console finalizer does, thus, crashing the app.

Seen this happen in VSMac.

Expected Behavior

The app does not crash and shuts down normally.

Actual Behavior

The app crashes.

Environment

=== Visual Studio Community 2019 (Preview) for Mac ===

Version 8.1 Preview (8.1 build 2056)
Installation UUID: 010a6a17-65d7-44f0-9e3d-48e5afe82e81
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 5.6.0.25 (d16-0 / 50f75273)

    Package version: 518010003

=== Mono Framework MDK ===

Runtime:
    Mono 5.18.1.3 (2018-08/fdb26b0a445) (64-bit)
    Package version: 518010003

=== NuGet ===

Version: 4.8.2.5835

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    3.0.0-preview-27122-01
    2.2.0
    2.1.9
    2.1.8
    2.1.7
    2.1.2
SDK: /usr/local/share/dotnet/sdk/3.0.100-preview-009812/Sdks
SDK Versions:
    3.0.100-preview-009812
    2.2.101
    2.2.100
    2.1.505
    2.1.504
    2.1.503
    2.1.302
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.18.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.9
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 10.1 (14460.46)
Build 10B61

=== Xamarin.Mac ===

Version: 5.6.0.25 (Visual Studio Community)
Hash: 50f75273
Branch: d16-0
Build date: 2019-03-05 11:50:33-0800

=== Xamarin.iOS ===

Version: 12.6.0.25 (Visual Studio Community)
Hash: 50f75273
Branch: d16-0
Build date: 2019-03-05 11:50:33-0800

=== Xamarin Designer ===

Version: 16.1.99.363
Hash: 47469594a
Branch: remotes/origin/new-document-model
Build date: 2019-04-12 20:06:42 UTC

=== Xamarin.Android ===

Version: 9.2.0.5 (Visual Studio Community)
Commit: HEAD/292d27fa
Android SDK: /Users/therzok/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        4.4    (API level 19)
        4.4.87 (API level 20)
        5.0    (API level 21)
        5.1    (API level 22)
        6.0    (API level 23)
        7.0    (API level 24)
        7.1    (API level 25)
        8.0    (API level 26)
        8.1    (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 27.0.0

Build Information: 
Mono: mono/mono/2018-08-rc@5ad371dab1b
Java.Interop: xamarin/java.interop/d16-0@c987483
LibZipSharp: grendello/LibZipSharp/master@44de300
LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
MXE: xamarin/mxe/xamarin@b9cbb535
ProGuard: xamarin/proguard/master@905836d
SQLite: xamarin/sqlite/3.26.0@325e91a
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-0@0a7edd6

=== Microsoft Mobile OpenJDK ===

Java SDK: /Users/therzok/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android Device Manager ===

Version: 1.2.0.46
Hash: a606a7c
Branch: remotes/origin/bump-ci-xammac-remove-old-scripts~4
Build date: 2019-04-11 18:51:42 UTC

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 801002056
Git revision: 1e79e8eee16b89facbdf93fa1f653fa7b8fc1564
Build date: 2019-04-15 13:30:46+00
Build branch: master
Xamarin extensions: f5be63b25b74079a5154c4518d10e6e2f89f46b6

=== Operating System ===

Mac OS X 10.14.4
Darwin 18.5.0 Darwin Kernel Version 18.5.0
    Mon Mar 11 20:40:32 PDT 2019
    root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

AddinMaker 1.5.0

Build Logs

Example Project (If Possible)

Found in VSMac, will possibly try to help with a repro if needed.

bug macOS need-info

All 6 comments

Can reproduce it if you SIGINT VSMac.

Forgot to post a stacktrace:

[ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Stream does not support writing
  at System.IO.FileStream.Write (System.Byte[] array, System.Int32 offset, System.Int32 count) [0x00099] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.IO/FileStream.cs:615
  at System.IO.StreamWriter.Flush (System.Boolean flushStream, System.Boolean flushEncoder) [0x0007e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/io/streamwriter.cs:318
  at System.IO.StreamWriter.Write (System.Char[] buffer, System.Int32 index, System.Int32 count) [0x000d3] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/io/streamwriter.cs:420
  at System.IO.CStreamWriter.Write (System.Char[] buffer, System.Int32 index, System.Int32 count) [0x00086] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/corlib/System/CStreamWriter.cs:94
  at System.IO.TextWriter.WriteLine (System.String value) [0x00070] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/io/textwriter.cs:490
  at System.IO.TextWriter+SyncTextWriter.WriteLine (System.String value) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-08/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/io/textwriter.cs:849
  at (wrapper synchronized) System.IO.TextWriter+SyncTextWriter.WriteLine(string)
  at Foundation.NSObject+Observer.Dispose (System.Boolean disposing) [0x00055] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.6.0.25/src/Xamarin.Mac/Foundation/NSObject2.cs:885
  at Foundation.NSObject.Finalize () [0x00002] in /Library/Frameworks/Xamarin.Mac.framework/Versions/5.6.0.25/src/Xamarin.Mac/Foundation/NSObject2.cs:143

@Therzok - What kind of observer are you using (there are a few was of observing things in XM)?

I tried a simple repro and I'm not seeing it.

I wonder if this isn't a mono bug: "Can't call Console.[Error].WriteLine after initializing AppDomain shutdown".

Could be mono. I'm back from holidays now so should be able to crop up a repro.

I'm even more confused as to why this is happening now.

SuppressFinalize is called for all the native streams (stdin, stdout, stderr). So that means something, somewhere, is setting their own Console.Err and disposing it, causing this crash to happen.

sigh

Was this page helpful?
0 / 5 - 0 ratings