Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluating a record with recursive reference results in termination of the program with Stack Overflow #48646

Closed
tmat opened this issue Oct 15, 2020 · 7 comments
Assignees
Labels
Area-Compilers Area-Interactive Interactive-Debugging Resolution-By Design The behavior reported in the issue matches the current design untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@tmat
Copy link
Member

tmat commented Oct 15, 2020

Version Used:
Version 16.9.0 Preview 1.0 [30614.203.main]

Steps to Reproduce:

Place breakpoint as indicated, F5 and open Locals Window, then step (F10).

record C
{
    public int X { get; init; }
    public int Y { get; init; }
    public int Z { get; init; }

    public C Inner { get; set; }
}

class Program
{
    static void Main(string[] args)
    {
        var c = new C();
        c.Inner = c; // breakpoint here
    }
}

Actual Behavior:

image

Expected Behavior:

SO is prevented.

Perhaps the implementation should only go to certain depth and then bail.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Interactive untriaged Issues and PRs which have not yet been triaged by a lead labels Oct 15, 2020
@RikkiGibson
Copy link
Contributor

Tagging @jcouv

@jcouv
Copy link
Member

jcouv commented Nov 4, 2020

That was discussed in LDM and is by-design. The ToString, GetHashCode and Equals implementations recurse without limit.
We recommend adding a debugger display or customizing ToString for such scenarios.

@jcouv jcouv added the Resolution-By Design The behavior reported in the issue matches the current design label Nov 4, 2020
@jcouv jcouv self-assigned this Nov 4, 2020
@tmat
Copy link
Member Author

tmat commented Nov 23, 2020

What was the reasoning for this design decision? Is the scenario deemed unlikely? Have you considered that the VS debugger evaluates ToString when the user hovers on a variable to show a data tip with the value of the variable? Hard crashing the debuggee process when hovering over source code is not a great experience. Also, customizing the record implementation might not be an option when debugging third party code.

Limiting the stack depth of ToString to some reasonable number (say 64) would be easy to implement. I believe other languages (e.g. Python and Ruby) do that in their object inspection methods.

If it is not possible to do so we could special case records in EE and not call ToString on them.

@PathogenDavid
Copy link
Contributor

PathogenDavid commented Nov 23, 2020

What was the reasoning for this design decision?

Here's the full LDM meeting notes from when this was discussed.

@jcouv jcouv removed their assignment May 19, 2021
@CyrusNajmabadi CyrusNajmabadi self-assigned this Jun 2, 2021
@CyrusNajmabadi
Copy link
Member

Assigning to myself to proceed with a WG to come up with a proposal here.

@CyrusNajmabadi
Copy link
Member

TAgging @cston @333fred @RikkiGibson @jcouv who all showed interest in this topic.

@RikkiGibson
Copy link
Contributor

Resolving this issue as the scenario described is now fixed. We now throw InsufficientExecutionStackException instead of actually overflowing the stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Area-Interactive Interactive-Debugging Resolution-By Design The behavior reported in the issue matches the current design untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

6 participants