Skip to content

Commit

Permalink
websocket connection fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kelindi committed Feb 11, 2025
1 parent abc19b9 commit eb0d108
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pkg/solver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ func (solverServer *solverServer) ListenAndServe(ctx context.Context, cm *system
exemptIPKeyFunc(exemptIPs),
httprate.KeyByEndpoint,
),
httprate.WithErrorHandler(func(w corehttp.ResponseWriter, r *corehttp.Request, err error) {
if err.Error() == "RATE_LIMIT_EXEMPT" {
httprate.WithLimitHandler(func(w corehttp.ResponseWriter, r *corehttp.Request) {

key, _ := exemptIPKeyFunc(exemptIPs)(r)
if strings.HasPrefix(key, "exempt-") {
return
}
corehttp.Error(w, err.Error(), corehttp.StatusTooManyRequests)

corehttp.Error(w, "Too Many Requests", corehttp.StatusTooManyRequests)
}),
))

Expand Down Expand Up @@ -198,13 +201,13 @@ func exemptIPKeyFunc(exemptIPs []string) func(r *corehttp.Request) (string, erro
ip, err := httprate.KeyByRealIP(r)
if err != nil {
log.Error().Err(err).Msg("error getting real ip")
return ip, err
return "", err
}

// Check if the IP is in the exempt list
for _, exemptIP := range exemptIPs {
if http.CanonicalizeIP(exemptIP) == ip {
return "", fmt.Errorf("RATE_LIMIT_EXEMPT")
return "exempt-" + ip, nil
}
}

Expand Down Expand Up @@ -769,7 +772,7 @@ func (solverServer *solverServer) updateJobStates(dealID string, state string) e
if err != nil {
return err
}

_, err = solverServer.controller.updateDealState(deal.Deal.ID, data.GetAgreementStateIndex(state))
if err != nil {
return err
Expand Down

0 comments on commit eb0d108

Please sign in to comment.