forked from mirrors/gotosocial
Compare commits
3 commits
main
...
programmat
Author | SHA1 | Date | |
---|---|---|---|
0dea2801bd | |||
631ec7e763 | |||
e1bd7a6cd7 |
|
@ -22,9 +22,12 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"reflect"
|
"reflect"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"runtime/debug"
|
||||||
|
"time"
|
||||||
|
|
||||||
"codeberg.org/gruf/go-runners"
|
"codeberg.org/gruf/go-runners"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/log"
|
"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",
|
log.Tracef("%s queueing message (queue=%d): %+v",
|
||||||
w.prefix, w.workers.Queue(), msg,
|
w.prefix, w.workers.Queue(), msg,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Take dump before entering func hook
|
||||||
|
dump := debug.Stack()
|
||||||
|
|
||||||
w.workers.Enqueue(func(ctx context.Context) {
|
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 {
|
if err := w.process(ctx, msg); err != nil {
|
||||||
log.Errorf("%s %v", w.prefix, err)
|
log.Errorf("%s %v", w.prefix, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,13 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"runtime/debug"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"codeberg.org/gruf/go-byteutil"
|
||||||
"codeberg.org/gruf/go-kv"
|
"codeberg.org/gruf/go-kv"
|
||||||
|
"codeberg.org/gruf/go-kv/format"
|
||||||
"github.com/superseriousbusiness/activity/streams/vocab"
|
"github.com/superseriousbusiness/activity/streams/vocab"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
"github.com/superseriousbusiness/gotosocial/internal/ap"
|
||||||
"github.com/superseriousbusiness/gotosocial/internal/config"
|
"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:
|
stackLoop:
|
||||||
for i := 0; i < maxIter; i++ {
|
for i := 0; i < maxIter; i++ {
|
||||||
// Pop next frame, nil means we are at end
|
// Pop next frame, nil means we are at end
|
||||||
|
|
Loading…
Reference in a new issue