forked from mirrors/gotosocial
Compare commits
3 commits
main
...
programmat
Author | SHA1 | Date | |
---|---|---|---|
0dea2801bd | |||
631ec7e763 | |||
e1bd7a6cd7 |
|
@ -22,9 +22,12 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-runners"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
||||
|
@ -116,7 +119,24 @@ func (w *WorkerPool[MsgType]) Queue(msg MsgType) {
|
|||
log.Tracef("%s queueing message (queue=%d): %+v",
|
||||
w.prefix, w.workers.Queue(), msg,
|
||||
)
|
||||
|
||||
// Take dump before entering func hook
|
||||
dump := debug.Stack()
|
||||
|
||||
w.workers.Enqueue(func(ctx context.Context) {
|
||||
t := time.AfterFunc(time.Minute*5, func() {
|
||||
// After 5 minutes, dump stacktrace and panic
|
||||
fmt.Fprintf(os.Stderr, "\n\n%s\n\n", dump)
|
||||
go panic("long-running worker function")
|
||||
})
|
||||
|
||||
defer func() {
|
||||
// Stop timer on exit
|
||||
if !t.Stop() {
|
||||
<-t.C
|
||||
}
|
||||
}()
|
||||
|
||||
if err := w.process(ctx, msg); err != nil {
|
||||
log.Errorf("%s %v", w.prefix, err)
|
||||
}
|
||||
|
|
|
@ -22,8 +22,13 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"codeberg.org/gruf/go-byteutil"
|
||||
"codeberg.org/gruf/go-kv"
|
||||
"codeberg.org/gruf/go-kv/format"
|
||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
||||
|
@ -189,6 +194,27 @@ func (d *deref) dereferenceStatusDescendants(ctx context.Context, username strin
|
|||
}
|
||||
)
|
||||
|
||||
// Take dump before entering func hook
|
||||
dump := debug.Stack()
|
||||
|
||||
t := time.AfterFunc(time.Minute*5, func() {
|
||||
var buf byteutil.Buffer
|
||||
|
||||
// Serialize current stack frame state
|
||||
format.Appendf(&buf, "{:?}", stack)
|
||||
|
||||
// After 5 minutes, dump stacktrace and stack state, and panic
|
||||
fmt.Fprintf(os.Stderr, "\n\n%s\n\n%s\n\n", dump, buf.String())
|
||||
go panic("long-running worker function")
|
||||
})
|
||||
|
||||
defer func() {
|
||||
// Stop timer on exit
|
||||
if !t.Stop() {
|
||||
<-t.C
|
||||
}
|
||||
}()
|
||||
|
||||
stackLoop:
|
||||
for i := 0; i < maxIter; i++ {
|
||||
// Pop next frame, nil means we are at end
|
||||
|
|
Loading…
Reference in a new issue