Compare commits

...

3 commits

Author SHA1 Message Date
tsmethurst 0dea2801bd Merge branch 'main' into programmatic-c4 2022-11-06 13:32:10 +01:00
tsmethurst 631ec7e763 Merge branch 'main' into programmatic-c4 2022-11-06 12:03:04 +01:00
kim e1bd7a6cd7 kim's special blend of debug-friendly programmatic C4
Signed-off-by: kim <grufwub@gmail.com>
2022-11-06 10:48:22 +00:00
2 changed files with 46 additions and 0 deletions

View file

@ -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)
}

View file

@ -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