Skip to content

Cannot print exception string because Exception.ToString() failed #6299

Closed

Description

@adityamandaleeka

This occurred on an Ubuntu CI job while running Base02d_seq_ser. The job appears to have been kicked off for this PR but I don't have any reason to believe it's related to the changes in that PR.

Dump and binaries: http://dotnetrp.azurewebsites.net/dumpling/download/1504

Activity

  1. adityamandaleeka commented on Jul 11, 2016

    @adityamandaleeka
    MemberAuthor

    Another example of this: http://dotnet-ci.cloudapp.net/job/dotnet_coreclr/job/master/job/checked_ubuntu_tst_prtest/3179

    This time in Loader/classloader/generics/Instantiation/Negative/abstract08

    Dump and binaries: http://dotnetrp.azurewebsites.net/dumpling/download/1507

  2. janvorli commented on Jul 11, 2016

    @janvorli
    Member

    As for the first dump (I haven't looked at the other yet), I can see that the formatting of the stack trace has failed due to the null reference exception:

    (lldb) pe
    Exception object: 00007f74a0017728
    Exception type:   System.NullReferenceException
    Message:          Object reference not set to an instance of an object.
    InnerException:   <none>
    StackTrace (generated):
        SP               IP               Function
        00007FFFF222B6D0 00007F78F00434D5 System.Private.CoreLib.dll!System.Text.StringBuilder.AppendFormatHelper(System.IFormatProvider, System.String, System.ParamsArray)+0x905
        00007FFFF222B760 00007F78F02CBF46 System.Private.CoreLib.dll!System.Diagnostics.StackTrace.ToString(TraceFormat)+0x266
        00007FFFF222B890 00007F78F0055A88 System.Private.CoreLib.dll!System.Exception.GetStackTrace(Boolean)+0x48
        00007FFFF222B8B0 00007F78F0055919 System.Private.CoreLib.dll!System.Exception.ToString(Boolean, Boolean)+0x189
        00007FFFF222B8F0 00007F78F0054DD8 System.Private.CoreLib.dll!System.Exception.InternalToString()+0x68
    
    StackTraceString: <none>
    HResult: 80004003
    

    Disassembling code around the failure point shows something strange:

    00007f78f00434c6 488b7db0             mov     rdi, qword ptr [rbp - 0x50]
    00007f78f00434ca 4885ff               test    rdi, rdi
    00007f78f00434cd 0f84aa000000         je      0x7f78f004357d
    00007f78f00434d3 33ff                 xor     edi, edi
    >>> 00007f78f00434d5 488b07               mov     rax, qword ptr [rdi]
    

    See the xor edi, edi? That means that the RDI would always be zero there! The function is quite long, but trying to match the source and the diassembly, it looks like the test rdi, rdi is the else if (arg != null) below:

                    if (s == null) {
                        IFormattable formattableArg = arg as IFormattable;
    
                        if (formattableArg != null) {
                            if (sFmt == null && fmt != null) {
                                sFmt = fmt.ToString();
                            }
    
                            s = formattableArg.ToString(sFmt, provider);
                        } else if (arg != null) {
                            s = arg.ToString();
                        }
                    }
  3. adityamandaleeka commented on Jul 11, 2016

    @adityamandaleeka
    MemberAuthor

    The second dump has exactly the same issue. I wonder if this is related to any recent JIT changes.

  4. adityamandaleeka commented on Jul 12, 2016

    @adityamandaleeka
    MemberAuthor

    I was curious about this so I dumped the disassembly for System.Private.CoreLib.dll!System.Text.StringBuilder.AppendFormatHelper from an older dump (from some unrelated run last week) and noticed that it's different (excerpts below):

    OLDER

        0x7ff23025fe50: movabsq $0x7ff230145118, %r11     ; imm = 0x7FF230145118 
        0x7ff23025fe5a: cmpl   %edi, (%rdi)
        0x7ff23025fe5c: callq  *(%r11)
        0x7ff23025fe5f: movq   %rax, -0x68(%rbp)
        0x7ff23025fe63: movl   -0x34(%rbp), %r8d
        0x7ff23025fe67: movl   -0x38(%rbp), %r9d
        0x7ff23025fe6b: jmp    0x7ff23025fe9b
        0x7ff23025fe6d: movq   %r10, -0x58(%rbp)
        0x7ff23025fe71: jmp    0x7ff23025fdaf
        0x7ff23025fe76: movq   -0x50(%rbp), %rcx
        0x7ff23025fe7a: testq  %rcx, %rcx
        0x7ff23025fe7d: je     0x7ff23025ff2e
        0x7ff23025fe83: movq   %rcx, %rdi
        0x7ff23025fe86: movq   (%rcx), %rax
        0x7ff23025fe89: movq   0x48(%rax), %rax
        0x7ff23025fe8d: callq  *(%rax)

    NEWER

        0x7ff635b9b4b0: movabsq $0x7ff635a8f0c0, %r11     ; imm = 0x7FF635A8F0C0 
        0x7ff635b9b4ba: cmpl   %edi, (%rdi)
        0x7ff635b9b4bc: callq  *(%r11)
        0x7ff635b9b4bf: movq   %rax, -0x68(%rbp)
        0x7ff635b9b4c3: movl   -0x34(%rbp), %r8d
        0x7ff635b9b4c7: movl   -0x38(%rbp), %r9d
        0x7ff635b9b4cb: jmp    0x7ff635b9b4fa
        0x7ff635b9b4cd: movq   %r10, -0x58(%rbp)
        0x7ff635b9b4d1: jmp    0x7ff635b9b40f
        0x7ff635b9b4d6: movq   -0x50(%rbp), %rdi
        0x7ff635b9b4da: testq  %rdi, %rdi
        0x7ff635b9b4dd: je     0x7ff635b9b58d
        0x7ff635b9b4e3: xorl   %edi, %edi
        0x7ff635b9b4e5: movq   (%rdi), %rax
        0x7ff635b9b4e8: movq   0x48(%rax), %rax
        0x7ff635b9b4ec: callq  *(%rax)
  5. parjong commented on Jul 12, 2016

    @parjong
    Contributor

    Is it related with #6283? The error log looks very similar.

  6. CarolEidt commented on Jul 12, 2016

    @CarolEidt
    Contributor

    I'm looking at this, while in parallel attempting to run the failing arm tests from #6283 on the emulator. Using the corerun from the 2nd dump location above, with a version of the test built locally, I would expect the code generated to be the same, since it is exactly the same jit.

  7. CarolEidt commented on Jul 13, 2016

    @CarolEidt
    Contributor

    I am unable to repro this with either test case. What's even stranger than the fact that the "this" pointer is being set to zero is that just above, it has been tested against zero. It's almost as if assertion prop has gotten it exactly backward (i.e. propagating null to this block instead of non-null), or that value numbering is incorrectly propagating the results of the IsInstanceOf call. If my dotnet/coreclr#6227 PR is indeed responsible for the arm failures in #6283 (which I'm still working on attempting to repro), it would be very surprising if it is the same issue as this, since this deals with object refs and my PR should affect only structs (unless, of course, there's some interaction that I haven't been able to see). @dotnet/jit-contrib - can anyone else think of something in the JIT that might determine that a ref's value is zero?

  8. swgillespie commented on Jul 15, 2016

    @swgillespie
    Contributor
  9. adityamandaleeka commented on Jul 15, 2016

    @adityamandaleeka
    MemberAuthor

    This just repro'd again on the Ubuntu job for PR dotnet/coreclr#6297

  10. RussKeldorph commented on Jul 27, 2016

    @RussKeldorph
    Contributor

    So presumably confirmed that this is indeed not due to dotnet/coreclr#6021 since that was backed out. The symptom became basically 100% repro on ARM after dotnet/coreclr#6021, though, so perhaps it would be better to investigate the problem there in case both the ARM failure and the x64 failure happen to be the same issue.

  11. CarolEidt commented on Jul 27, 2016

    @CarolEidt
    Contributor

    @papaslavik has identified the root cause of at least one of the arm failures (#6459) that seems to be similar to this. We have both been looking into potential solutions. Of course, there's no guarantee that it is the same root cause as this, but since it is an issue of using uninitialized data in assertion prop (and the bad code generated here has the appearance of being bad assertion prop), it could very well be.

  12. CarolEidt commented on Jul 27, 2016

    @CarolEidt
    Contributor

    @adityamandaleeka - I just merged a PR (#6484) that fixes a problem with assertion prop using uninitialized data. I am hoping these intermittent failures are addressed by that as well. Please let me know if you encounter more of these failures.

  13. 8 remaining items

  14. abelbraaksma commented on Jun 24, 2020

    @abelbraaksma
    Contributor

    @reinux, do you happen to still have the details of your issue? Yours seems to be related to F#, and I encounter it now as well, see this PR: dotnet/fsharp#9549 (specifically here: dotnet/fsharp#9549 (comment)). Or did you report it elsewhere? I've difficulty pinning it down...

  15. reinux commented on Jun 24, 2020

    @reinux

    @abelbraaksma @danmosemsft Nuts. I totally missed this, and now that I've tried it again, I can't reproduce the problem.

    Really sorry about that.

    As far as I remember, though, that was all there was to it. No other changes to the project, no other errors.

    I wish I could be of more help.

  16. abelbraaksma commented on Jun 25, 2020

    @abelbraaksma
    Contributor

    @reinux, no worries, these things happen ;). Anyway, I do have a repro now, I'll report it separately if I can isolate it.

  17. reinux commented on Jul 4, 2020

    @reinux

    Okay, it's happening again, this time using the IdentityModel package.

    .NET Core 3.1, only depending on IdentityModel 4.3.0, Newtonsoft.Json 12.0.3 and System.Text.Encodings.Web 4.7.1.

    The entirety of code:

    open System.Net.Http
    open IdentityModel.Client
    
    let client = new HttpClient()
    
    let disco =
      client.GetDiscoveryDocumentAsync("http://localhost:7000")
      |> Async.AwaitTask |> Async.RunSynchronously
    
    [<EntryPoint>]
    let main argv =
        0 // return an integer exit code
    
  18. reinux commented on Jul 4, 2020

    @reinux

    I also noticed something strange:

    Trying to use the GetDiscoveryDocumentAsync extension method from IdentityModel.Client, Visual Studio recognizes it, but FSI doesn't see it at all.

    Normally, if I'm missing some references or something, VS would know. So I think that's probably what the error was trying to tell me.

    Would you happen to know if there might be a workaround?

  19. abelbraaksma commented on Jul 4, 2020

    @abelbraaksma
    Contributor

    @reinux, You happen to run into similar issues while I'm also working on it. I suspect that the reason this error is thrown is caused by a combination of two things:

    • While compiling, the references are fine, but when running or inspecting the code, they are not. This leads to types not being found. Normally this would give a "reference not found error"
    • When an exception is raised, this exception may not have ToString() or Message overridden. If that isn't overridden, the base Exception class calls GetClassName(), which in turn calls GetType(). I suspect that this throws, which then in turn leads to the very confusing error "Cannot print exception string because Exception.ToString() failed".

    What complicates matters is that with F# there can be difference between inlined and not-inlined functions. This means that while compiling, the reference is needed, but when running, it isn't. Furthermore, the inlining itself can lead to a dependency that you wouldn't have had when the inlining didn't happen (this has to do with optimizations). Whether that's the case here remains to be seen.

    I have yet to confirm this analysis. But if true, I think that a solution shouldn't be too hard, I hope.

  20. abelbraaksma commented on Jul 4, 2020

    @abelbraaksma
    Contributor

    @reinux please open a new issue. Also more info: .NET version it's running on, and what happens under a debugger.

    We should probably do what @danmosemsft suggests here. As this original issue is closed. Could you do the honors of creating an issue for F# with your repro here: https://github.com/dotnet/fsharp/issues?

  21. reinux commented on Jul 4, 2020

    @reinux

    Running it in the VS debugger, I get this exception, which is really bonkers:

    System.TypeInitializationException
      HResult=0x80131534
      Message=The type initializer for '<StartupCode$TestClient2>.$Program' threw an exception.
      Source=TestClient2
      StackTrace:
       at Program.main(String[] argv) in C:\Users\rei\source\repos\AoiFrontDesk\TestClient2\Program.fs:line 12
    
    Inner Exception 1:
    FileNotFoundException: Could not load file or assembly 'FSharp.Core, Version=4.7.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
    
  22. reinux commented on Jul 4, 2020

    @reinux

    Could you do the honors of creating an issue for F# with your repro here: https://github.com/dotnet/fsharp/issues?

    All right, let me dig in a little deeper to see if I can isolate the issue more, because the conditions for it to occur seem to have changed on me...

  23. reinux commented on Jul 4, 2020

    @reinux

    @abelbraaksma Are you using paket by any chance? If I add a reference to IdentityModel using paket, then remove the reference, the problem persists.

    But if I just add using dotnet add package, it seems to be fine.

    I think this is the problem: fsprojects/Paket#3721

  24. abelbraaksma commented on Jul 4, 2020

    @abelbraaksma
    Contributor

    No, I'm working on optimizations for FSharp.Core.dll and it runs certain tests that, after my optimizations, exhibited this error. All points to references, indeed. But I don't think it is isolated with Paket, at least not for me.

    But whatever the repro, the error as shown here should simply not be raised. I mean, the TypeInitializationException is kind of "normal" and can be solved (it indicates a bug by itself), but the "Cannot print exception string" certainly shouldn't happen, unless it was caused by deliberately evil user code.

  25. reinux commented on Jul 4, 2020

    @reinux

    It seems to be because this version of paket (which I just realized is 5 months old now...) is removing FSharp.Core.dll. So my theory currently is this:

    1. There's a call being made to something in FSharp.Core either before or inside Exception.ToString()
    2. Either VS debugger doesn't use Exception.ToString() so it shows TypeInitializationException instead, or it tries to call FSharp.Core.dll for some other purpose prior, and notices it's missing
    3. dotnet run, on the other hand, just shows this "not-even-an-exception error message" because they didn't expect top-level exception handling to depend in any way on a (potentially missing) library.

    I have a really strong hunch that updating paket will fix this problem for me, and so it's probably not going to be reproducible in this way for other people with the steps I used.

    Just wanted to run it by you before I do, in case you can think of a good way to express this problem to whomever might be in a position to improve it, which is kind of starting to look like more the dotnet runtime people if anything.

    Hmm...

  26. abelbraaksma commented on Jul 4, 2020

    @abelbraaksma
    Contributor

    Looks like your reference to the Paket issue, and your analysis, all point in the same direction: a missing dll, specifically FSharp.Core.

    I still feel it shouldn't throw that error "cannot print etc", even though we know the cause.

    The reason you see the type load exception, is because when debugging, you see the first chance exceptions. If there's no debugger attached, it goes to the exception handler (which defaults to printing the error, which it can't).

  27. reinux commented on Jul 4, 2020

    @reinux

    I still feel it shouldn't throw that error "cannot print etc", even though we know the cause.

    I agree. It would have saved me a lot of time if the message were more specific. Maybe I'll bring that up on https://github.com/dotnet/runtime/issues .

    The reason you see the type load exception, is because when debugging, you see the first chance exceptions.

    Oh right, I forgot about that.

    Edit: Side note: The problem with the GetDiscoveryDocumentAsync extension method not being found by FSI seems to be unrelated. Referencing the extension method by its actual name seems to work:

    IdentityModel.Client.HttpClientDiscoveryExtensions.GetDiscoveryDocumentAsync( client, address = "https://localhost:7000")

    Tried a few experiments with async extension methods with default parameters and such, but I couldn't nail down exactly why this is happening with this particular method.

  28. ghost locked as resolved and limited conversation to collaborators on Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions