datastar 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/datastar/dispatcher.rb +23 -6
- data/lib/datastar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6fc6011ed2e49835f82ef6345c457f7e50812d155802ca722a9abb7858bffcc6
|
|
4
|
+
data.tar.gz: 6849ec8942f01e3d252e2bfdc77902bb4901663a2baa153fd72e421b64336915
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 895e948c8ea3cb095768c409fc6fcb9cec2d31c20fa41c47ac0131af35729aeb8ee0138d880cd70e9ec06d893101791e8a1d5db73355496f69bbe0242e9a03f1
|
|
7
|
+
data.tar.gz: f7f10819510f6b69757b2982cf71bbe31a8504688e5efd575cc077a97e183e17f16b5d10a830bcb8966eec4076cfac2bcb2faddc74b355288cb6ec8d21dd97d4
|
data/lib/datastar/dispatcher.rb
CHANGED
|
@@ -386,14 +386,33 @@ module Datastar
|
|
|
386
386
|
@compressor.wrap_socket(socket)
|
|
387
387
|
end
|
|
388
388
|
|
|
389
|
+
# Errors raised when writing to a socket the client has closed.
|
|
390
|
+
DISCONNECT_ERRORS = [IOError, Errno::EPIPE, Errno::ECONNRESET].freeze
|
|
391
|
+
|
|
392
|
+
# Whether an error means the client went away.
|
|
393
|
+
#
|
|
394
|
+
# Servers may wrap the underlying socket error in their own class
|
|
395
|
+
# (e.g. protocol-http1 >= 0.41 raises +Protocol::HTTP::RemoteError+
|
|
396
|
+
# from a +rescue Errno::EPIPE+), so the +cause+ chain is checked too.
|
|
397
|
+
#
|
|
398
|
+
# @param error [Exception]
|
|
399
|
+
# @return [Boolean]
|
|
400
|
+
def client_disconnect?(error)
|
|
401
|
+
while error
|
|
402
|
+
return true if DISCONNECT_ERRORS.any? { |klass| error.is_a?(klass) }
|
|
403
|
+
|
|
404
|
+
error = error.cause
|
|
405
|
+
end
|
|
406
|
+
false
|
|
407
|
+
end
|
|
408
|
+
|
|
389
409
|
# Handle errors caught during streaming
|
|
390
410
|
# @param error [Exception] the error that occurred
|
|
391
411
|
# @param socket [IO] the socket to pass to error handlers
|
|
392
412
|
def handle_streaming_error(error, socket)
|
|
393
|
-
|
|
394
|
-
when IOError, Errno::EPIPE, Errno::ECONNRESET
|
|
413
|
+
if client_disconnect?(error)
|
|
395
414
|
@on_client_disconnect.each { |callable| callable.call(socket) }
|
|
396
|
-
|
|
415
|
+
else
|
|
397
416
|
@on_error.each { |callable| callable.call(error) }
|
|
398
417
|
end
|
|
399
418
|
end
|
|
@@ -407,10 +426,8 @@ module Datastar
|
|
|
407
426
|
yield
|
|
408
427
|
|
|
409
428
|
@on_server_disconnect.each { |callable| callable.call(generator) }
|
|
410
|
-
rescue IOError, Errno::EPIPE, Errno::ECONNRESET => e
|
|
411
|
-
@on_client_disconnect.each { |callable| callable.call(socket) }
|
|
412
429
|
rescue Exception => e
|
|
413
|
-
|
|
430
|
+
handle_streaming_error(e, socket)
|
|
414
431
|
end
|
|
415
432
|
|
|
416
433
|
# Parse signals from the request
|
data/lib/datastar/version.rb
CHANGED