Skip to content

Commit

Permalink
Added stack trace to the panic recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
onur-yildirim-infinitusai committed Jan 7, 2025
1 parent 42c3486 commit 5a3960f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/client/common/v1/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"strings"
"time"
"runtime/debug"

"github.com/dvonthenen/websocket"
klog "k8s.io/klog/v2"
Expand Down Expand Up @@ -265,6 +266,8 @@ func (c *WSClient) listen() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := ErrFatalPanicRecovered
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/listen/v1/websocket/client_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io"
"regexp"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -246,6 +247,8 @@ func (c *WSCallback) ping() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := common.ErrFatalPanicRecovered
Expand Down Expand Up @@ -289,6 +292,8 @@ func (c *WSCallback) flush() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := common.ErrFatalPanicRecovered
Expand Down
5 changes: 5 additions & 0 deletions pkg/client/listen/v1/websocket/client_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"fmt"
"io"
"regexp"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -246,6 +247,8 @@ func (c *WSChannel) ping() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := common.ErrFatalPanicRecovered
Expand Down Expand Up @@ -289,6 +292,8 @@ func (c *WSChannel) flush() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := common.ErrFatalPanicRecovered
Expand Down
3 changes: 3 additions & 0 deletions pkg/client/speak/v1/websocket/client_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -213,6 +214,8 @@ func (c *WSCallback) flush() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := common.ErrFatalPanicRecovered
Expand Down
5 changes: 4 additions & 1 deletion pkg/client/speak/v1/websocket/client_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/json"
"fmt"
"regexp"
"runtime/debug"
"strings"
"time"

Expand Down Expand Up @@ -212,12 +213,14 @@ func (c *WSChannel) flush() {
defer func() {
if r := recover(); r != nil {
klog.V(1).Infof("Panic triggered\n")
klog.V(1).Infof("Panic: %v\n", r)
klog.V(1).Infof("Stack trace: %s\n", string(debug.Stack()))

// send error on callback
err := common.ErrFatalPanicRecovered
sendErr := c.ProcessError(err)
if sendErr != nil {
klog.V(1).Infof("listen: Fatal socket error. Err: %v\n", sendErr)
klog.V(1).Infof("speak: Fatal socket error. Err: %v\n", sendErr)
}

klog.V(6).Infof("speak.flush() LEAVE\n")
Expand Down

0 comments on commit 5a3960f

Please sign in to comment.