@@ -70,7 +70,6 @@ type RelayConnection struct {
70
70
eventsToSendMutex sync.Mutex
71
71
newEventsCh chan domain.Event
72
72
rateLimitNoticeBackoffManager * RateLimitNoticeBackoffManager
73
- cancelBackPressure context.CancelFunc
74
73
}
75
74
76
75
func NewRelayConnection (
@@ -90,7 +89,6 @@ func NewRelayConnection(
90
89
eventsToSend : make (map [domain.EventId ]* eventToSend ),
91
90
newEventsCh : make (chan domain.Event ),
92
91
rateLimitNoticeBackoffManager : rateLimitNoticeBackoffManager ,
93
- cancelBackPressure : nil ,
94
92
}
95
93
}
96
94
@@ -108,10 +106,6 @@ func (r *RelayConnection) Run(ctx context.Context) {
108
106
if r .Address ().HostWithoutPort () == "relay.nos.social" {
109
107
// We control relay.nos.social, so we don't backoff here
110
108
backoff = 0
111
- } else if errors .Is (err , BackPressureError ) {
112
- // Only calling r.cancelBackPressure() can resolve the backpressure
113
- r .WaitUntilNoBackPressure (ctx )
114
- backoff = 0
115
109
}
116
110
117
111
select {
@@ -123,20 +117,6 @@ func (r *RelayConnection) Run(ctx context.Context) {
123
117
}
124
118
}
125
119
126
- func (r * RelayConnection ) WaitUntilNoBackPressure (ctx context.Context ) {
127
- var resolvedBackPressureCtx context.Context
128
- var cancelBackPressure context.CancelFunc
129
-
130
- r .setStateWithFn (RelayConnectionStateBackPressured , func () {
131
- resolvedBackPressureCtx , cancelBackPressure = context .WithCancel (ctx )
132
- r .cancelBackPressure = cancelBackPressure
133
- })
134
-
135
- <- resolvedBackPressureCtx .Done ()
136
-
137
- r .setState (RelayConnectionStateDisconnected )
138
- }
139
-
140
120
func (r * RelayConnection ) State () RelayConnectionState {
141
121
r .stateMutex .Lock ()
142
122
defer r .stateMutex .Unlock ()
@@ -356,8 +336,8 @@ func (r *RelayConnection) run(ctx context.Context) error {
356
336
}
357
337
358
338
if r .state == RelayConnectionStateBackPressured {
359
- // Load shedding under backpressure
360
- continue
339
+ // Load shedding under backpressure, we just disconnect
340
+ return BackPressureError
361
341
}
362
342
363
343
if err := r .handleMessage (messageBytes ); err != nil {
@@ -613,14 +593,6 @@ func (r *RelayConnection) setState(state RelayConnectionState) {
613
593
r .state = state
614
594
}
615
595
616
- func (r * RelayConnection ) setStateWithFn (state RelayConnectionState , fn func ()) {
617
- r .stateMutex .Lock ()
618
- defer r .stateMutex .Unlock ()
619
-
620
- r .state = state
621
- fn ()
622
- }
623
-
624
596
func (r * RelayConnection ) manageSubs (ctx context.Context , conn Connection ) error {
625
597
defer conn .Close ()
626
598
0 commit comments