Browse Source

Refactor error handling in `publisher.go`, comment redundant logging in `acl/follows.go`, and improve error handling for connection rejections (403).

main
mleku 4 months ago
parent
commit
8290e1ae0e
No known key found for this signature in database
  1. 4
      app/publisher.go
  2. 19
      pkg/acl/follows.go

4
app/publisher.go

@ -15,7 +15,7 @@ import (
"next.orly.dev/pkg/encoders/kind" "next.orly.dev/pkg/encoders/kind"
"next.orly.dev/pkg/interfaces/publisher" "next.orly.dev/pkg/interfaces/publisher"
"next.orly.dev/pkg/interfaces/typer" "next.orly.dev/pkg/interfaces/typer"
utils "next.orly.dev/pkg/utils" "next.orly.dev/pkg/utils"
) )
const Type = "socketapi" const Type = "socketapi"
@ -229,7 +229,7 @@ func (p *P) Deliver(ev *event.E) {
if err = d.w.Write( if err = d.w.Write(
writeCtx, websocket.MessageText, res.Marshal(nil), writeCtx, websocket.MessageText, res.Marshal(nil),
); chk.E(err) { ); err != nil {
// On error, remove the subscriber connection safely // On error, remove the subscriber connection safely
p.removeSubscriber(d.w) p.removeSubscriber(d.w)
_ = d.w.CloseNow() _ = d.w.CloseNow()

19
pkg/acl/follows.go

@ -79,7 +79,7 @@ func (f *Follows) Configure(cfg ...any) (err error) {
} else { } else {
adm = a adm = a
} }
log.I.F("admin: %0x", adm) // log.I.F("admin: %0x", adm)
f.admins = append(f.admins, adm) f.admins = append(f.admins, adm)
fl := &filter.F{ fl := &filter.F{
Authors: tag.NewFromAny(adm), Authors: tag.NewFromAny(adm),
@ -229,6 +229,15 @@ func (f *Follows) startSubscriptions(ctx context.Context) {
c, _, err := websocket.Dial(ctx, u, nil) c, _, err := websocket.Dial(ctx, u, nil)
if err != nil { if err != nil {
log.W.F("follows syncer: dial %s failed: %v", u, err) 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) timer := time.NewTimer(backoff)
select { select {
case <-ctx.Done(): case <-ctx.Done():
@ -300,10 +309,10 @@ func (f *Follows) startSubscriptions(ctx context.Context) {
if f.pubs != nil { if f.pubs != nil {
go f.pubs.Deliver(res.Event) go f.pubs.Deliver(res.Event)
} }
log.I.F( // log.I.F(
"saved new event from follows syncer: %0x", // "saved new event from follows syncer: %0x",
res.Event.ID, // res.Event.ID,
) // )
} }
case eoseenvelope.L: case eoseenvelope.L:
// ignore, continue subscription // ignore, continue subscription

Loading…
Cancel
Save