clickhouse-native 0.11.0-x86_64-linux-gnu → 0.11.1-x86_64-linux-gnu

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6186352daf6afcb3b55c2b1839055b8d4bc1d414067f6c52bf6353cfce221d5
4
- data.tar.gz: e5b25c22dc3d3e66987a3d5c03bf1e91829507b5cc6c31522e96adaa6a820554
3
+ metadata.gz: e9a219a37184b5d629cc1916479bb3dbe098b067f18885fd3b1d10bc8850c210
4
+ data.tar.gz: 10b0e67501598683eab560a5c52819aaa45c0f525d0e2eac3ec6a4cd3b3096b0
5
5
  SHA512:
6
- metadata.gz: b37f44e1705a8a5fef335e8be1b7b493e1b5622721b4bfa9d13133b7ab14d44d3fab4ee0b3128bfdfc0c809544804b72678bbe4491d206233fda75443777ca14
7
- data.tar.gz: 97605a75f445c3b74360aec37c247cd0219eb741894e4623504481afe2ae7deabe63c9aa3638377e68f07ddb562e42c4c504c9ad1a6274aa3959d7315392ba90
6
+ metadata.gz: c9163043fb4a3e18c1fc6a824808cd22aebc8c964eb7f24a4dff5b30f3acaa7562f55142ce3c8f72acaca3835fd95dd5f09737833d4eea65d706bf6abbffb838
7
+ data.tar.gz: 4859cd3547d8e16cf7417b1ca1fb9b56924cb75b329d5942a36112480767384eccae03144140fe46e9d58a75d4ca64f2ff2aebad0339d63515c61499d97e9337
@@ -22,8 +22,8 @@ module ClickhouseNative
22
22
  end
23
23
  end
24
24
 
25
- # On exception, discard the client rather than reuse it: an error
26
- # path leaves the socket in an unknown state. The C++ binding issues
25
+ # On an aborted operation, discard the client rather than reuse it: the
26
+ # socket is left in an unknown state. The C++ binding issues
27
27
  # ResetConnection, but a subsequent send can still surface buffered
28
28
  # protocol errors from the prior aborted operation — those get
29
29
  # attributed to whatever SQL we tried next, producing misleading log
@@ -44,15 +44,18 @@ module ClickhouseNative
44
44
  # before running the query, so most stale connections never surface as
45
45
  # a ConnectionError here at all. This retry still covers the residual
46
46
  # race (socket dies between the ping and the query).
47
+ #
48
+ # A bare `rescue` is not enough to spot an abandoned query. Timeout and
49
+ # Sidekiq shutdown raise off Exception rather than StandardError, and
50
+ # Thread#kill raises nothing at all — Parallel.in_threads kills every
51
+ # sibling worker the moment one of them fails. Miss those and the
52
+ # connection goes back in with the server still streaming a response at
53
+ # it; the next checkout reads that leftover as its own, which surfaces
54
+ # as a bogus packet type far from here.
47
55
  def with
48
56
  attempts = 0
49
57
  begin
50
- @pool.with do |client|
51
- yield client
52
- rescue
53
- @pool.discard_current_connection(&:close)
54
- raise
55
- end
58
+ @pool.with { |client| discard_unless_clean { yield client } }
56
59
  rescue ConnectionError
57
60
  attempts += 1
58
61
  retry if attempts == 1
@@ -91,5 +94,30 @@ module ClickhouseNative
91
94
  def describe_table(table, db_name: nil)
92
95
  with { |c| c.describe_table(table, db_name:) }
93
96
  end
97
+
98
+ private
99
+
100
+ # Keep the client only when the block either finished or left of its own
101
+ # accord. A `break` out of a streaming read is deliberate, and the binding
102
+ # has already reconnected the client on its way out (query_each resets the
103
+ # connection before rb_jump_tag), so it is good to reuse — discarding would
104
+ # buy a second connect on top of the one already paid. An exception is an
105
+ # abort, and so is Thread#kill: it raises nothing, so no rescue ever sees
106
+ # it, and its only trace is an "aborting" thread while ensure runs.
107
+ def discard_unless_clean
108
+ finished = false
109
+ begin
110
+ result = yield
111
+ finished = true
112
+ result
113
+ rescue Exception # rubocop:disable Lint/RescueException
114
+ @pool.discard_current_connection(&:close)
115
+ raise
116
+ ensure
117
+ if !finished && Thread.current.status == "aborting"
118
+ @pool.discard_current_connection(&:close)
119
+ end
120
+ end
121
+ end
94
122
  end
95
123
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickhouseNative
4
- VERSION = "0.11.0"
4
+ VERSION = "0.11.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clickhouse-native
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.1
5
5
  platform: x86_64-linux-gnu
6
6
  authors:
7
7
  - Yuri Smirnov