Skip to content

Commit a85b94c

Browse files
committed
added backoff to push retry
1 parent 65ddeda commit a85b94c

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lib/splitclient-rb/engine/sync_manager.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(config,
2323
@push_manager = push_manager
2424
@status_queue = status_queue
2525
@sse_connected = Concurrent::AtomicBoolean.new(false)
26+
@back_off = Engine::BackOff.new(5, 3)
2627
end
2728

2829
def start
@@ -119,7 +120,7 @@ def process_forced_stop
119120
end
120121

121122
def process_disconnect(reconnect)
122-
unless @sse_connected.value
123+
unless @sse_connected.value || reconnect
123124
@config.logger.debug('Streaming already disconnected.') if @config.debug_enabled
124125
return
125126
end
@@ -130,6 +131,9 @@ def process_disconnect(reconnect)
130131
record_telemetry(Telemetry::Domain::Constants::SYNC_MODE, SYNC_MODE_POLLING)
131132

132133
if reconnect
134+
wait_interval = @back_off.interval
135+
@config.logger.debug("Retrying streaming connection in: #{wait_interval} seconds")
136+
sleep(wait_interval)
133137
@push_manager.stop_sse
134138
@synchronizer.sync_all
135139
@push_manager.start_sse
@@ -155,6 +159,7 @@ def incoming_push_status_handler
155159

156160
case status
157161
when Constants::PUSH_CONNECTED
162+
@back_off.reset
158163
process_connected
159164
when Constants::PUSH_RETRYABLE_ERROR
160165
process_disconnect(true)

0 commit comments

Comments
 (0)