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

cmd/dlv: print out message with stack trace when breakpoint is hit but has no waiting client #3632

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

fatanugraha
Copy link

@fatanugraha fatanugraha commented Jan 15, 2024

Print out a message and stack trace to the stderr when we hit a breakpoint and the client that sends the continue command has disconnected.

Fixes #3469

@fatanugraha fatanugraha force-pushed the support-disable-panic-catcher branch 2 times, most recently from c12a582 to 66a3316 Compare January 15, 2024 18:04
Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think that needing this option is a strong symptom that there is something very wrong with your development environment. In the context of running something locally during development you would want the program to stop at a panic to examine why the panic happened.
In the context of running the program in production having a debugger attached to it constantly is a security risk.

@derekparker
Copy link
Member

I'm also inclined to agree with @aarzilli, however I am familiar with the workflow described in the associated issue, and in that context I could see the benefit to the actual crash being apparent and not silenced by Delve by virtue of waiting on user input to produce the panic.

My initial feedback is I am against wholesale deletion of these breakpoints, I think it would be better to actually disable them, so they can be re-enabled later without having to know the specifics of the runtime.

@aarzilli
Copy link
Member

We could also print something if we stop at a breakpoint while there isn't a connected client.

@derekparker
Copy link
Member

We could also print something if we stop at a breakpoint while there isn't a connected client.

That's good too. Might even be nice to print the traceback and panic message automatically when hitting the panic breakpoints anyways, to be honest.

@fatanugraha
Copy link
Author

I still think that needing this option is a strong symptom that there is something very wrong with your development environment.

I agree with you. This option is needed in our orgs because not everyone are familiar with the debugger and we want to have a setup that is practical and convenient for everyone.

My initial feedback is I am against wholesale deletion of these breakpoints, I think it would be better to actually disable them, so they can be re-enabled later without having to know the specifics of the runtime.

I tried this one actually, instead of deleting them I tried to toggling off those breakpoints, but it's not possible to do that through the API because we will reject any request that has - in it. If we're okay with changing the API behaviour I can adjust the MR to do this instead.

That's good too. Might even be nice to print the traceback and panic message automatically when hitting the panic breakpoints anyways, to be honest.

Ideally yeah this is what I'm looking for, but it seems to be a bit tricky to pull off. Let me see if i can find a way to do this.

@aarzilli
Copy link
Member

Ideally yeah this is what I'm looking for, but it seems to be a bit tricky to pull off. Let me see if i can find a way to do this.

One way to do it would be like this:

  • There's a function in service/rpccommon/server.go called serveJSONCodec, that's the function that serves requests from a client. You can have a boolean there that you set to false when that function exits and check it in (*RPCCallback).Return.

  • This boolean needs to be protected with a mutex so you could copy the syncflag type in service/dap/server.go.

  • Have (*RPCCallback).Return return false if the client has quit and then print something in (*RPCServer).Command in service/rpc2/server.go

@fatanugraha fatanugraha changed the title cmd/dlv: add --disable-break-on-panic to disable panic handler breakpoint auto creation cmd/dlv: print out message for multi accept mode on panic/fatalthrow Jan 25, 2024
@fatanugraha
Copy link
Author

One way to do it would be like this:

oh ya i have implemented this in this PR but in a different fashion.

Might even be nice to print the traceback and panic message automatically when hitting the panic breakpoints anyways, to be honest.

Initially im thinking to move the unhandled panic breakpoint to somewhere after we print out the message but it's going to be a bit tricky to make it sure it works for older (and future) go versions so I'm going with implementing this on the server side. Hope that's acceptable.

Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this was a leftover comment)

_fixtures/fatalthrow.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
@derekparker
Copy link
Member

Hey @fatanugraha there has been no update on this PR in a month, are you still planning to work on this?

@fatanugraha
Copy link
Author

Hi @derekparker I have plans to pick this up again in 1-2 weeks from now, but if anyone else wants to work on this issue I'm also okay with that. Sorry for the delay :(

@derekparker
Copy link
Member

Hi @derekparker I have plans to pick this up again in 1-2 weeks from now, but if anyone else wants to work on this issue I'm also okay with that. Sorry for the delay :(

No worries, and no rush! Just wanted to check in.

service/rpc2/server.go Outdated Show resolved Hide resolved
@TomK
Copy link

TomK commented Apr 5, 2024

@fatanugraha would you like some additional hands on this?
I'm happy to make the changes suggested by @aarzilli

@fatanugraha fatanugraha force-pushed the support-disable-panic-catcher branch from cf2069e to c9531a9 Compare April 7, 2024 07:48
@fatanugraha
Copy link
Author

fatanugraha commented Apr 7, 2024

Hey folks, sorry for the bad delays. Here's how it looks right now if we hit a breakpoint (screenshot below is when we hit the panic/fatal bp) but the client that sends the continue gone already

Screenshot 2024-04-07 at 15 49 09

@fatanugraha fatanugraha changed the title cmd/dlv: print out message for multi accept mode on panic/fatalthrow cmd/dlv: print out message with stack trace when breakpoint is hit but has no waiting clients Apr 7, 2024
@fatanugraha fatanugraha changed the title cmd/dlv: print out message with stack trace when breakpoint is hit but has no waiting clients cmd/dlv: print out message with stack trace when breakpoint is hit but has no waiting client Apr 7, 2024
cmd/dlv/dlv_test.go Outdated Show resolved Hide resolved
service/rpc2/server.go Outdated Show resolved Hide resolved
@fatanugraha fatanugraha force-pushed the support-disable-panic-catcher branch from ac5dd6c to 593758a Compare April 17, 2024 16:24
service/rpccommon/server.go Outdated Show resolved Hide resolved
service/debugger/debugger.go Outdated Show resolved Hide resolved
service/dap/server.go Outdated Show resolved Hide resolved
@fatanugraha
Copy link
Author

Sorry folks for the long delay, life got in the way 😅

@fatanugraha fatanugraha force-pushed the support-disable-panic-catcher branch from 9a37b4b to ae15db6 Compare May 30, 2024 17:34
@fatanugraha fatanugraha force-pushed the support-disable-panic-catcher branch from ae15db6 to 6667b65 Compare May 30, 2024 17:35
Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this is good, except for a couple of changes that may have been caused by a merge conflict. Also could you remove all the extra newlines that you have added at various points.

service/dap/server.go Outdated Show resolved Hide resolved
service/debugger/debugger.go Outdated Show resolved Hide resolved
Copy link
Member

@aarzilli aarzilli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

@TomK
Copy link

TomK commented Jun 1, 2024

Great work @fatanugraha 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: headless startup without break-on-panic
4 participants