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

Hard to repro bug: screen locks sometimes #3605

Closed
thockin opened this issue Dec 22, 2023 · 8 comments · Fixed by #3619
Closed

Hard to repro bug: screen locks sometimes #3605

thockin opened this issue Dec 22, 2023 · 8 comments · Fixed by #3619

Comments

@thockin
Copy link
Contributor

thockin commented Dec 22, 2023

  1. What version of Delve are you using (dlv version)?

Delve Debugger
Version: 1.21.1
Build: $Id: a358c02f24aa7047ecc562b0587dc2d08330b2cf $

  1. What version of Go are you using? (go version)?

go version go1.21.3 linux/amd64

  1. What operating system and processor architecture are you using?

linux amd64

  1. What did you do?

Ran dlv, hit ^Z

  1. What did you expect to see?

My terminal

  1. What did you see instead?

Frozen screen, no input or output. I had to killall -9 dlv from another terminal, at which point all of the buffered input was sent to shell! And I had to reset the terminal.

I can't 100% repro this, but it happened several times yesterday. Not sure how to debug it.

@thockin
Copy link
Contributor Author

thockin commented Dec 24, 2023

It keeps happening - any clues on how to debug it would be helpful.

@aarzilli
Copy link
Member

Are you hitting ^Z while the program you are debugging is running or at delve's prompt?
If you look at the output of ps what does it say about dlv?
Can you use delve to attach to the stuck dlv process and see what it's doing?

@thockin
Copy link
Contributor Author

thockin commented Dec 25, 2023

^Z while in dlv

 ps auxw | grep dlv
thockin  3468313  1.5  0.1 6322216 83956 pts/0   Tl+  15:07   0:00 dlv debug ./staging/src/k8s.io/code-generator/cmd/defaulter-gen -- --v 5 --logtostderr -h hack/boilerplate/boilerplate.generatego.txt -O zz_generated.defaults -i ./cmd/kubeadm/app/apis/kubeadm/v1beta3 -i ./cmd/kubeadm/app/apis/kubeadm/v1beta4 -i ./pkg/apis/abac/v1beta1 -i ./pkg/apis/admission/v1 
$ dlv attach 3468313
Could not attach to pid 3468313: this could be caused by a kernel security setting, try writing "0" to /proc/sys/kernel/yama/ptrace_scope

sudo ~thockin/go/bin/dlv attach 3468313
Type 'help' for list of commands.

(dlv) grs
  Goroutine 1 - User: /home/thockin/go/pkg/mod/github.com/go-delve/liner@v1.2.3-0.20220127212407-d32d89dd2a5d/input.go:140 github.com/go-delve/liner.(*State).readNext (0x9537be) [select]
  Goroutine 2 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [force gc (idle) 1631637529423568]
  Goroutine 3 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [GC sweep wait]
  Goroutine 4 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [GC scavenge wait]
  Goroutine 5 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [finalizer wait 1631637529423568]
  Goroutine 6 - User: /home/thockin/go/pkg/mod/github.com/go-delve/delve@v1.21.2/pkg/proc/native/proc.go:400 github.com/go-delve/delve/pkg/proc/native.(*ptraceThread).handlePtraceFuncs (0x892457) [chan receive]
  Goroutine 7 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [debug call]
  Goroutine 13 - User: /home/thockin/sdk/gotip/src/net/pipe.go:159 net.(*pipe).read (0x565a35) [select]
  Goroutine 15 - User: /home/thockin/sdk/gotip/src/runtime/internal/syscall/syscall_linux.go:38 syscall.RawSyscall6 (0x407ced) (thread 3468317)
  Goroutine 18 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [debug call]
  Goroutine 19 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [debug call]
  Goroutine 20 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [debug call]
  Goroutine 21 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [select 1631637748260353]
  Goroutine 34 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [debug call]
  Goroutine 35 - User: /home/thockin/sdk/gotip/src/runtime/proc.go:403 runtime.gopark (0x44090e) [debug call]
  Goroutine 51 - User: /home/thockin/sdk/gotip/src/net/pipe.go:159 net.(*pipe).read (0x565a35) [select]
  Goroutine 53 - User: /home/thockin/sdk/gotip/src/runtime/sigqueue.go:152 os/signal.signal_recv (0x46f929) (thread 3468319)
  Goroutine 55 - User: /home/thockin/go/pkg/mod/github.com/go-delve/delve@v1.21.2/pkg/terminal/terminal.go:186 github.com/go-delve/delve/pkg/terminal.(*Term).sigintGuard (0x99f4bd) [chan receive 1631637748260353]
[18 goroutines]

Here's my config, in case it matters:

(dlv) config -list
aliases                   map[display:[disp] down:[do] help:[?]]
substitute-path           []
max-string-len            256
max-array-values          4
max-variable-recurse      2
disassemble-flavor        <not defined>
show-location-expr        false
source-list-line-color    "\x1b[0;33m"
source-list-arrow-color   "\x1b[1;36m"
source-list-keyword-color "\x1b[0;34m"
source-list-string-color  "\x1b[0;35m"
source-list-number-color  "\x1b[0;32m"
source-list-comment-color "\x1b[0;36m"
source-list-tab-color     "\x1b[2;37m"
source-list-line-count    10
debug-info-directories    [/usr/lib/debug/.build-id]
position                  ""
tab                       "... "
trace-show-timestamp      false

It seems to happen 100% now for me, but when I sud dlv attach'ed I could ^Z ok.

@aarzilli
Copy link
Member

The 'T' status looks fine, it means dlv did suspend in response to the signal. What's not good is the '+', at that point the shell should take over the terminal. What's the environment here: shell, terminal, any terminal multiplexes involved, ssh, is any of this being started by a script?

@thockin
Copy link
Contributor Author

thockin commented Dec 26, 2023 via email

@thockin
Copy link
Contributor Author

thockin commented Dec 26, 2023

hah, that does seem to trigger it. I admit I don't know enough about how the terminal SHOULD react to say if this is right or not. I tested by putting vi in a script and ^Zing that works how I would expect (the whole shell suspends).

$ cat vi.sh 
#!/bin/sh
echo before
vi "$@"
echo after

$ echo $SHLVL
1

$ sh vi.sh /tmp/a
before
<vi loaded, I hit ^Z>
[1]+  Stopped                 sh vi.sh /tmp/a

$ echo $SHLVL
1

$ fg
<vi reloaded, I exited>
sh vi.sh /tmp/a
after

Is that a fair analog? I think so but not 100% sure.

aarzilli added a commit to aarzilli/liner that referenced this issue Dec 27, 2023
To correctly mimic the behavior of a terminal we need to send SIGTSTP
to the whole foreground process group, instead of just sending it to
ourselves.

Fixes go-delve/delve#3605
@aarzilli
Copy link
Member

We're sending SIGTSTP to ourselves when we should be sending it to our process group. The workaround for this should be to have an actual exec in the script (exec dlv debug ...)

@thockin
Copy link
Contributor Author

thockin commented Dec 27, 2023

Yes, exec fixes the problem for now. Thanks for digging in.

derekparker pushed a commit to go-delve/liner that referenced this issue Dec 31, 2023
To correctly mimic the behavior of a terminal we need to send SIGTSTP
to the whole foreground process group, instead of just sending it to
ourselves.

Fixes go-delve/delve#3605
aarzilli added a commit to aarzilli/delve that referenced this issue Jan 2, 2024
Update version of go-delve/liner to include the Ctrl-Z fix (SIGTSTP
should be sent to our process group instead of just sending it to
ourselves to correctly imitate a terminal).

Fixes go-delve#3605
derekparker pushed a commit that referenced this issue Jan 3, 2024
Update version of go-delve/liner to include the Ctrl-Z fix (SIGTSTP
should be sent to our process group instead of just sending it to
ourselves to correctly imitate a terminal).

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

Successfully merging a pull request may close this issue.

2 participants