Skip to content

Commit

Permalink
fix: Add user agent and fix backoff socket dialer logic
Browse files Browse the repository at this point in the history
The websocket backoff logic was not properly configured and so would
relentlessly spam the web socket endpoint with connect requests. Woops.

Also provide a user agent in the header when requesting to be polite
with server.
  • Loading branch information
snorremd committed Nov 19, 2024
1 parent 6a0f3c4 commit 172a63a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions firehose/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"fmt"
"net/http"
"norsky/models"
"strings"
"time"
Expand All @@ -25,12 +26,21 @@ import (
// Subscribe to the firehose using the Firehose struct as a receiver
func Subscribe(ctx context.Context, postChan chan interface{}, ticker *time.Ticker, seq int64) {
address := "wss://bsky.network/xrpc/com.atproto.sync.subscribeRepos"
headers := http.Header{}
headers.Set("User-Agent", "NorSky: https://github.com/snorremd/norsky")

if seq >= 0 {
log.Info("Starting from sequence: ", seq)
address = fmt.Sprintf("%s?cursor=%d", address, seq)
}
// Identify dialer with User-Agent header

dialer := websocket.DefaultDialer
backoff := backoff.NewExponentialBackOff()
backoff.InitialInterval = 3 * time.Second
backoff.MaxInterval = 30 * time.Second
backoff.Multiplier = 1.5
backoff.MaxElapsedTime = 120 * time.Second

// Check if context is cancelled, if so exit the connection loop
for {
Expand Down

0 comments on commit 172a63a

Please sign in to comment.