Skip to content

Commit

Permalink
Merge pull request #272 from onur-yildirim-infinitusai/adding-stack-t…
Browse files Browse the repository at this point in the history
…race-for-panics

fix: enhance panic error logging in SDK by adding stack trace
  • Loading branch information
naomi-lgbt authored Feb 13, 2025
2 parents 8b673cd + 7abe92b commit 2a89eda
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 @@ -271,6 +272,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 2a89eda

Please sign in to comment.