From 8290e1ae0ec4a35c27fb6c1cec8c7e9eb95ac0aa Mon Sep 17 00:00:00 2001 From: mleku Date: Sat, 13 Sep 2025 09:07:33 +0100 Subject: [PATCH] Refactor error handling in `publisher.go`, comment redundant logging in `acl/follows.go`, and improve error handling for connection rejections (403). --- app/publisher.go | 4 ++-- pkg/acl/follows.go | 19 ++++++++++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/publisher.go b/app/publisher.go index c5fa4f1..bf5ff75 100644 --- a/app/publisher.go +++ b/app/publisher.go @@ -15,7 +15,7 @@ import ( "next.orly.dev/pkg/encoders/kind" "next.orly.dev/pkg/interfaces/publisher" "next.orly.dev/pkg/interfaces/typer" - utils "next.orly.dev/pkg/utils" + "next.orly.dev/pkg/utils" ) const Type = "socketapi" @@ -229,7 +229,7 @@ func (p *P) Deliver(ev *event.E) { if err = d.w.Write( writeCtx, websocket.MessageText, res.Marshal(nil), - ); chk.E(err) { + ); err != nil { // On error, remove the subscriber connection safely p.removeSubscriber(d.w) _ = d.w.CloseNow() diff --git a/pkg/acl/follows.go b/pkg/acl/follows.go index f835507..fcdae3d 100644 --- a/pkg/acl/follows.go +++ b/pkg/acl/follows.go @@ -79,7 +79,7 @@ func (f *Follows) Configure(cfg ...any) (err error) { } else { adm = a } - log.I.F("admin: %0x", adm) + // log.I.F("admin: %0x", adm) f.admins = append(f.admins, adm) fl := &filter.F{ Authors: tag.NewFromAny(adm), @@ -229,6 +229,15 @@ func (f *Follows) startSubscriptions(ctx context.Context) { c, _, err := websocket.Dial(ctx, u, nil) if err != nil { log.W.F("follows syncer: dial %s failed: %v", u, err) + if strings.Contains( + err.Error(), "response status code 101 but got 403", + ) { + // 403 means the relay is not accepting connections from + // us. Forbidden is the meaning, usually used to + // indicate either the IP or user is blocked. so stop + // trying this one. + return + } timer := time.NewTimer(backoff) select { case <-ctx.Done(): @@ -300,10 +309,10 @@ func (f *Follows) startSubscriptions(ctx context.Context) { if f.pubs != nil { go f.pubs.Deliver(res.Event) } - log.I.F( - "saved new event from follows syncer: %0x", - res.Event.ID, - ) + // log.I.F( + // "saved new event from follows syncer: %0x", + // res.Event.ID, + // ) } case eoseenvelope.L: // ignore, continue subscription