@@ -41,9 +41,12 @@ def close(status = nil)
4141 @config . logger . debug ( 'SSEClient already disconected.' )
4242 return
4343 end
44+ @config . logger . debug ( "Closing SSEClient socket" )
4445
4546 @connected . make_false
47+ @socket . sync_close = true
4648 @socket . close
49+ @config . logger . debug ( "SSEClient socket state #{ @socket . state } " )
4750 push_status ( status )
4851 rescue StandardError => e
4952 @config . logger . error ( "SSEClient close Error: #{ e . inspect } " )
@@ -86,39 +89,43 @@ def connect_thread(latch)
8689 def connect_stream ( latch )
8790 return Constants ::PUSH_NONRETRYABLE_ERROR unless socket_write ( latch )
8891 while connected? || @first_event . value
89- if IO . select ( [ @socket ] , nil , nil , @read_timeout )
90- begin
91- partial_data = @socket . readpartial ( 10_000 )
92- read_first_event ( partial_data , latch )
93-
94- raise 'eof exception' if partial_data == :eof
95- rescue IO ::WaitReadable => e
96- @config . logger . debug ( "SSE client IO::WaitReadable transient error: #{ e . inspect } " )
97- IO . select ( [ @socket ] , nil , nil , @read_timeout )
98- retry
99- rescue Errno ::EAGAIN => e
100- @config . logger . debug ( "SSE client transient error: #{ e . inspect } " )
101- IO . select ( [ @socket ] , nil , nil , @read_timeout )
102- retry
103- rescue Errno ::ETIMEDOUT => e
104- @config . logger . error ( "SSE read operation timed out!: #{ e . inspect } " )
105- return Constants ::PUSH_RETRYABLE_ERROR
106- rescue EOFError => e
107- @config . logger . error ( "SSE read operation EOF Exception!: #{ e . inspect } " )
108- raise 'eof exception'
109- rescue Errno ::EBADF , IOError => e
110- @config . logger . error ( "SSE read operation EBADF or IOError: #{ e . inspect } " )
111- return Constants ::PUSH_RETRYABLE_ERROR
112- rescue StandardError => e
113- @config . logger . error ( "SSE read operation StandardError: #{ e . inspect } " )
114- return nil if ENV [ 'SPLITCLIENT_ENV' ] == 'test'
115-
116- @config . logger . error ( "Error reading partial data: #{ e . inspect } " )
92+ begin
93+ if IO . select ( [ @socket ] , nil , nil , @read_timeout )
94+ begin
95+ partial_data = @socket . readpartial ( 10_000 )
96+ read_first_event ( partial_data , latch )
97+
98+ raise 'eof exception' if partial_data == :eof
99+ rescue IO ::WaitReadable => e
100+ @config . logger . debug ( "SSE client IO::WaitReadable transient error: #{ e . inspect } " )
101+ IO . select ( [ @socket ] , nil , nil , @read_timeout )
102+ retry
103+ rescue Errno ::EAGAIN => e
104+ @config . logger . debug ( "SSE client transient error: #{ e . inspect } " )
105+ IO . select ( [ @socket ] , nil , nil , @read_timeout )
106+ retry
107+ rescue Errno ::ETIMEDOUT => e
108+ @config . logger . error ( "SSE read operation timed out!: #{ e . inspect } " )
109+ return Constants ::PUSH_RETRYABLE_ERROR
110+ rescue EOFError => e
111+ @config . logger . error ( "SSE read operation EOF Exception!: #{ e . inspect } " )
112+ raise 'eof exception'
113+ rescue Errno ::EBADF , IOError => e
114+ @config . logger . error ( "SSE read operation EBADF or IOError: #{ e . inspect } " )
115+ return Constants ::PUSH_RETRYABLE_ERROR
116+ rescue StandardError => e
117+ @config . logger . error ( "SSE read operation StandardError: #{ e . inspect } " )
118+ return nil if ENV [ 'SPLITCLIENT_ENV' ] == 'test'
119+
120+ @config . logger . error ( "Error reading partial data: #{ e . inspect } " )
121+ return Constants ::PUSH_RETRYABLE_ERROR
122+ end
123+ else
124+ @config . logger . error ( "SSE read operation timed out, no data available." )
117125 return Constants ::PUSH_RETRYABLE_ERROR
118126 end
119- else
120- @config . logger . error ( "SSE read operation timed out, no data available." )
121- return Constants ::PUSH_RETRYABLE_ERROR
127+ rescue Errno ::EBADF
128+ @config . logger . debug ( "SSE socket is not connected (Errno::EBADF)" )
122129 end
123130
124131 process_data ( partial_data )
0 commit comments