tina4ruby 3.13.161 → 3.13.163

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: 819ee4d3aa8004a8ab9c4a36f0bf6ae4448da8025695a24d20609f96d2ef6cf4
4
- data.tar.gz: a2d690efa933ac65508944f721dab4d9cf31268853276a782ec30329f47c8d0b
3
+ metadata.gz: 34f4ce86795d403ce1236cfcdd459faa59f11fd43f7cf9d3a9a3dc9d13ec5209
4
+ data.tar.gz: 1a613e2d130a451750e228b99daf2e33bba88b5378bdd5ccb83cd99f1fbc05c7
5
5
  SHA512:
6
- metadata.gz: d363d16ad9e5aecd10fd33d448ab57d8d7d16c96d0a0946a648de15ec7d29bcd6025042532d97fde774711e8453dbf943a96d63c3f8b3216230bcd1f4e19f22d
7
- data.tar.gz: c3301274025ad604123048130bea9efe11b3c47261f3109bc81effcd9d29b14df2fd98462c33ed3e748c53bf3ace9dd84b54bbcdd95e543d906c5d8aadb8ae93
6
+ metadata.gz: 60c7c05fee96e02aa8320b77e2ab0b6a1ed9458cc5456bcfb18284dc8ff4f1e5a1f0ee03e1056c0004590ef19e2f17c56c6466fd53665b0accb0fae356c39cda
7
+ data.tar.gz: 0232f479a2f5bcd8fa9e3cf0940ffcf717d2940919656762151b3abf6e6f88e4f2527715a483f5bfbb515d7772f97457ccb7b7c316125a845e2eb6ddbf958e42
data/CHANGELOG.md CHANGED
@@ -6,6 +6,18 @@ number means the same thing everywhere.
6
6
  **The authoritative release notes for every shipped version live in the documentation:**
7
7
  https://tina4.com/ruby/36-releases
8
8
 
9
+ ## 3.13.163 - 2026-11-13
10
+
11
+ ### Fixed
12
+
13
+ - A Kafka tombstone (a null-value record, such as a Debezium delete marker) no longer stops a consumer short. 3.13.162 stopped the crash but answered a tombstone with `nil`, so a single-pass drain (`consume(poll_interval: 0)`) read it as an empty queue: the records behind it were never reached, and a fresh process stopped at the same offset on every run. The poll loop now skips tombstones and keeps polling, still bounded by `dequeue`'s deadline (1 s steady state, the assign timeout on first subscribe). Nothing is committed on the tombstone path: acknowledging the next record commits past the skipped tombstones, so a restart gets past them. Acknowledge, retry and dead-letter are unchanged. Verified against a live broker producing real tombstones (#169, parity with tina4-python#309, tina4-php#357, tina4-nodejs#194).
14
+
15
+ ## 3.13.162 - 2026-11-10
16
+
17
+ ### Fixed
18
+
19
+ - Kafka tombstone (null-value) records no longer crash the consumer (tina4-python#303 twin). A tombstone — a record whose value is `null` (Debezium deletes, log-compacted delete markers) — reached `Tina4.parse_json(msg.payload)` on the rdkafka path, and `JSON.parse(nil)` raised `TypeError`, which `rescue Rdkafka::RdkafkaError` did not catch, so it escaped and killed the consumer; because the tombstone sits at the committed offset it was a poison pill that re-crashed on every restart. `dequeue` and the `dead_letters` reader now skip a `nil`-payload record and continue, so a following real record is still delivered. No mocks — driven against a real librdkafka producer/broker (#167).
20
+
9
21
  ## 3.13.161 - 2026-11-09
10
22
 
11
23
  ### Fixed
@@ -150,37 +150,11 @@ module Tina4
150
150
  # TINA4_KAFKA_ASSIGN_TIMEOUT, default 15s); steady state stays one ~1s poll.
151
151
  deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) +
152
152
  (first ? (ENV["TINA4_KAFKA_ASSIGN_TIMEOUT"] || "15").to_f : 1.0)
153
- msg = nil
154
- loop do
155
- candidate = @consumer.poll(500)
156
- if candidate
157
- msg = candidate
158
- break
159
- end
160
- break if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
161
- end
153
+ msg = poll_past_tombstones(deadline)
162
154
  return nil unless msg
163
155
 
164
- data = Tina4.parse_json(msg.payload)
165
- coordinate = "#{topic}:#{msg.partition}:#{msg.offset}"
166
-
167
- # A record carrying a "payload" key is a Tina4 envelope: keep its own id
168
- # (falling back to the coordinate) and carry attempts/error back so a
169
- # redelivery does not reset the count and re-produce a poison record
170
- # forever. A record WITHOUT one is externally produced (Debezium/CDC and
171
- # friends, no envelope, no id -- tina4#274): its whole value IS the
172
- # payload, and the coordinate becomes its id. Either way the job gets the
173
- # id acknowledge() maps back to this record's offset.
174
- job =
175
- if data.is_a?(Hash) && data.key?("payload")
176
- id = data["id"].to_s.empty? ? coordinate : data["id"]
177
- Tina4::Job.new(
178
- topic: topic, payload: data["payload"], id: id,
179
- attempts: data["attempts"] || 0, error: data["error"]
180
- )
181
- else
182
- Tina4::Job.new(topic: topic, payload: data, id: coordinate, attempts: 0)
183
- end
156
+ job = job_from_message(topic, msg)
157
+ return nil unless job
184
158
 
185
159
  @in_flight[job.id.to_s] = msg
186
160
  job
@@ -188,6 +162,55 @@ module Tina4
188
162
  nil
189
163
  end
190
164
 
165
+ # Poll until a record with a value arrives or the deadline passes.
166
+ #
167
+ # A tombstone carries no job: skip it and poll on. Returning nil at the
168
+ # first one read as an empty queue, so a single-pass drain
169
+ # (consume(poll_interval: 0)) stopped at the tombstone. The deadline holds
170
+ # while skipping too: a steady stream of tombstones must not hold dequeue
171
+ # past it. Nothing is committed here: acknowledging the next record commits
172
+ # past the skipped tombstones, as before.
173
+ def poll_past_tombstones(deadline)
174
+ loop do
175
+ candidate = @consumer.poll(500)
176
+ return candidate if candidate && !candidate.payload.nil?
177
+ return nil if Process.clock_gettime(Process::CLOCK_MONOTONIC) >= deadline
178
+ end
179
+ end
180
+
181
+ # Build a Job from a polled record, or nil for a record that carries no job.
182
+ #
183
+ # A null-value record is a tombstone / delete marker: Debezium emits these on
184
+ # deletes and log-compacted topics use them as delete markers, so they are
185
+ # normal on Kafka. rdkafka hands back a nil payload for one; return nil (skip
186
+ # it) so dequeue advances past it. Before this guard, JSON.parse(nil) raised a
187
+ # TypeError that dequeue's `rescue Rdkafka::RdkafkaError` did NOT catch, so the
188
+ # tombstone was a poison pill that killed the consumer on every restart
189
+ # (tina4-python#303, same crash in the rdkafka path).
190
+ #
191
+ # A record carrying a "payload" key is a Tina4 envelope: keep its own id
192
+ # (falling back to the coordinate) and carry attempts/error back so a
193
+ # redelivery does not reset the count and re-produce a poison record forever.
194
+ # A record WITHOUT one is externally produced (Debezium/CDC and friends, no
195
+ # envelope, no id -- tina4#274): its whole value IS the payload, and the
196
+ # coordinate becomes its id. Either way the job gets the id acknowledge()
197
+ # maps back to this record's offset.
198
+ def job_from_message(topic, msg)
199
+ return nil if msg.payload.nil?
200
+
201
+ data = Tina4.parse_json(msg.payload)
202
+ coordinate = "#{topic}:#{msg.partition}:#{msg.offset}"
203
+ if data.is_a?(Hash) && data.key?("payload")
204
+ id = data["id"].to_s.empty? ? coordinate : data["id"]
205
+ Tina4::Job.new(
206
+ topic: topic, payload: data["payload"], id: id,
207
+ attempts: data["attempts"] || 0, error: data["error"]
208
+ )
209
+ else
210
+ Tina4::Job.new(topic: topic, payload: data, id: coordinate, attempts: 0)
211
+ end
212
+ end
213
+
191
214
  # Kafka has no queue depth: a log is a sequence of offsets, not a queue,
192
215
  # and computing a "remaining" count means an admin round-trip per call.
193
216
  # ADR-0022 decision 5 records 0 as the documented answer, which Python and
@@ -287,6 +310,11 @@ module Tina4
287
310
  loop do
288
311
  msg = reader.poll(500)
289
312
  if msg
313
+ # Skip a tombstone / null-value record the same way dequeue does, so
314
+ # a null-value dead-letter never crashes the reader on JSON.parse(nil)
315
+ # (tina4-python#303).
316
+ next if msg.payload.nil?
317
+
290
318
  data = Tina4.parse_json(msg.payload)
291
319
  data["status"] = "dead"
292
320
  out << data
@@ -72,17 +72,29 @@ module Tina4
72
72
  return if @shutting_down
73
73
 
74
74
  @shutting_down = true
75
- Tina4::Log.info("Shutdown signal received, stopping gracefully...")
76
75
 
77
- stop_accepting
78
- drained = wait_for_in_flight
79
- release_resources
80
-
81
- Tina4::Log.info("Shutdown complete")
76
+ # The whole teardown runs INSIDE the signal handler's thread
77
+ # (install_signal_handlers). An exception escaping here - a failing log
78
+ # sink under TINA4_LOG_STRICT, a half-closed WebSocket, a dead database
79
+ # driver, Log.reset - would kill that thread mid-teardown. If it dies
80
+ # BEFORE stop_accepting, the listening socket never closes and the
81
+ # process HANGS on a signal that MUST drain and exit 0; if it dies
82
+ # later, resources leak. So every step degrades independently
83
+ # (guard_teardown) and the critical ones still run even when an earlier
84
+ # step threw - mirrors the per-step try/catch(\Throwable) in PHP's
85
+ # Server::cleanup()/stop().
86
+ guard_teardown { Tina4::Log.info("Shutdown signal received, stopping gracefully...") }
87
+ guard_teardown { stop_accepting }
88
+
89
+ drained = true
90
+ guard_teardown { drained = wait_for_in_flight }
91
+ guard_teardown { release_resources }
92
+
93
+ guard_teardown { Tina4::Log.info("Shutdown complete") }
82
94
  # Graceful shutdown owns the final call to reset() (Decision 24 /
83
95
  # LOG-I02): flush+close owned sinks AFTER the shutdown record above,
84
96
  # exactly once.
85
- Tina4::Log.reset
97
+ guard_teardown { Tina4::Log.reset }
86
98
  @shutdown_complete = true
87
99
  return if drained
88
100
 
@@ -139,6 +151,23 @@ module Tina4
139
151
 
140
152
  private
141
153
 
154
+ # Run one teardown step so that NO exception escapes the signal handler's
155
+ # thread (see initiate_shutdown). On a failure, degrade to a best-effort
156
+ # Tina4::Log.error; if the logger itself is what failed (a strict log sink
157
+ # that raises on write), fall back to $stderr so the degrade is never
158
+ # silent - then carry on, so the shutdown still completes and the process
159
+ # still exits 0. Keeps shutdown idempotent and exception-safe without
160
+ # changing the teardown order.
161
+ def guard_teardown
162
+ yield
163
+ rescue StandardError => e
164
+ begin
165
+ Tina4::Log.error("Error during graceful shutdown: #{e.class}: #{e.message}")
166
+ rescue StandardError
167
+ warn("tina4: graceful shutdown step failed: #{e.class}: #{e.message}")
168
+ end
169
+ end
170
+
142
171
  # TINA4_SHUTDOWN_TIMEOUT in seconds (same name and default in all four
143
172
  # frameworks). An unparseable or negative value warns and falls back to the
144
173
  # default: `"abc".to_i` is 0, and a silent 0-second drain would force-close
data/lib/tina4/version.rb CHANGED
@@ -7,5 +7,5 @@
7
7
 
8
8
 
9
9
  module Tina4
10
- VERSION = "3.13.161"
10
+ VERSION = "3.13.163"
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tina4ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.161
4
+ version: 3.13.163
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tina4 Team
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-11-09 00:00:00.000000000 Z
11
+ date: 2026-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3