tina4ruby 3.13.160 → 3.13.162

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: 04d0f0c9549b131ac6cc66c25af963c658b14a34c5f1690c17c46b2df16b0ab5
4
- data.tar.gz: 8ae3b7fb96142e89e7db778c790f45b53b763e1d2531870bbda84a5cf5422c83
3
+ metadata.gz: 15151f90c7170c25e2174fdf43bbf5c847c65478b082dd5bdbda8049a5b57b97
4
+ data.tar.gz: a040ce2ecad0cfe976a1eb579c001e07c4f9f27244f8c1e35591ba1b536ea8cc
5
5
  SHA512:
6
- metadata.gz: 5f50bfc2ae1a344b6398760b720caf2fc50cf9b18858ce64c2cd2ea1be4422537952a74028c34aea84244bd84e42e05f387f3c1e7830be48b7eaca7c0d8d58f7
7
- data.tar.gz: 3a8666bf0297807ddaee244b20d64e187dd76af5d8004555f10b19c79e6015d5620e42f86fab423b16ba6ac85d7d0347028491659798967cc36626e756e80547
6
+ metadata.gz: e1a7d0ff48f5310c2ee54a8d33c78bdfdcbdb1480a7633136cbde22cdea58c2e8b4f27845d1a21a14c79e4f4789c8b9fc009ec0bd61026a639ee0842598279c4
7
+ data.tar.gz: 1bead80a66a17fe802aac1efdd010695e884966c0b6848bfe18d6892899bd6f48e0854303afb67f303532649302201eb85ffcee7308b2cef304e2cd03f9ae2e4
data/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ 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.162 - 2026-11-10
10
+
11
+ ### Fixed
12
+
13
+ - 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).
14
+
15
+ ## 3.13.161 - 2026-11-09
16
+
17
+ ### Fixed
18
+
19
+ - TestClient now loads `.env` the way the app does (first-wins, `.env.local` then `.env`), so a test that does not boot the app still sees `TINA4_SECRET` and other variables instead of failing with a misleading error that points at `.env` (#296).
20
+ - `TestResponse` response-header lookups are now case-insensitive, matching `get_all`, so an assertion like `headers["Location"]` finds a header emitted as `location` instead of returning nil; the stored shape (lower-case keys, last value, emission order) is unchanged (#300).
21
+
9
22
  ## 3.13.160 - 2026-11-07
10
23
 
11
24
  ### Fixed
@@ -161,26 +161,8 @@ module Tina4
161
161
  end
162
162
  return nil unless msg
163
163
 
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
164
+ job = job_from_message(topic, msg)
165
+ return nil unless job
184
166
 
185
167
  @in_flight[job.id.to_s] = msg
186
168
  job
@@ -188,6 +170,39 @@ module Tina4
188
170
  nil
189
171
  end
190
172
 
173
+ # Build a Job from a polled record, or nil for a record that carries no job.
174
+ #
175
+ # A null-value record is a tombstone / delete marker: Debezium emits these on
176
+ # deletes and log-compacted topics use them as delete markers, so they are
177
+ # normal on Kafka. rdkafka hands back a nil payload for one; return nil (skip
178
+ # it) so dequeue advances past it. Before this guard, JSON.parse(nil) raised a
179
+ # TypeError that dequeue's `rescue Rdkafka::RdkafkaError` did NOT catch, so the
180
+ # tombstone was a poison pill that killed the consumer on every restart
181
+ # (tina4-python#303, same crash in the rdkafka path).
182
+ #
183
+ # A record carrying a "payload" key is a Tina4 envelope: keep its own id
184
+ # (falling back to the coordinate) and carry attempts/error back so a
185
+ # redelivery does not reset the count and re-produce a poison record forever.
186
+ # A record WITHOUT one is externally produced (Debezium/CDC and friends, no
187
+ # envelope, no id -- tina4#274): its whole value IS the payload, and the
188
+ # coordinate becomes its id. Either way the job gets the id acknowledge()
189
+ # maps back to this record's offset.
190
+ def job_from_message(topic, msg)
191
+ return nil if msg.payload.nil?
192
+
193
+ data = Tina4.parse_json(msg.payload)
194
+ coordinate = "#{topic}:#{msg.partition}:#{msg.offset}"
195
+ if data.is_a?(Hash) && data.key?("payload")
196
+ id = data["id"].to_s.empty? ? coordinate : data["id"]
197
+ Tina4::Job.new(
198
+ topic: topic, payload: data["payload"], id: id,
199
+ attempts: data["attempts"] || 0, error: data["error"]
200
+ )
201
+ else
202
+ Tina4::Job.new(topic: topic, payload: data, id: coordinate, attempts: 0)
203
+ end
204
+ end
205
+
191
206
  # Kafka has no queue depth: a log is a sequence of offsets, not a queue,
192
207
  # and computing a "remaining" count means an admin round-trip per call.
193
208
  # ADR-0022 decision 5 records 0 as the documented answer, which Python and
@@ -287,6 +302,11 @@ module Tina4
287
302
  loop do
288
303
  msg = reader.poll(500)
289
304
  if msg
305
+ # Skip a tombstone / null-value record the same way dequeue does, so
306
+ # a null-value dead-letter never crashes the reader on JSON.parse(nil)
307
+ # (tina4-python#303).
308
+ next if msg.payload.nil?
309
+
290
310
  data = Tina4.parse_json(msg.payload)
291
311
  data["status"] = "dead"
292
312
  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
@@ -23,6 +23,40 @@ require "stringio" # rack.input is a StringIO; require it here so a clean `requi
23
23
  require_relative "parse_json"
24
24
 
25
25
  module Tina4
26
+ # A Hash whose STRING key lookups are case-insensitive (#300).
27
+ #
28
+ # HTTP header names are case-insensitive (RFC 9110), and get_all already
29
+ # treats them that way. Keys are STORED down-cased, so iteration order, the
30
+ # key set, and the last-value-per-name view are all unchanged — every reader
31
+ # sees the same Hash. Only the LOOKUP down-cases the requested name, so
32
+ # headers["Location"] finds a header emitted as "location" instead of nil.
33
+ class CaseInsensitiveHeaders < Hash
34
+ def [](key)
35
+ super(normalise_key(key))
36
+ end
37
+
38
+ def fetch(key, *args, &block)
39
+ super(normalise_key(key), *args, &block)
40
+ end
41
+
42
+ def key?(key)
43
+ super(normalise_key(key))
44
+ end
45
+ alias has_key? key?
46
+ alias include? key?
47
+ alias member? key?
48
+
49
+ def dig(key, *rest)
50
+ super(normalise_key(key), *rest)
51
+ end
52
+
53
+ private
54
+
55
+ def normalise_key(key)
56
+ key.is_a?(String) ? key.downcase : key
57
+ end
58
+ end
59
+
26
60
  class TestResponse
27
61
  attr_reader :status, :body, :headers, :content_type
28
62
 
@@ -43,7 +77,7 @@ module Tina4
43
77
  # (never-repeated) header sees any change (TC-HEADER-COLLAPSE,
44
78
  # TC-DEC-02).
45
79
  @header_list = {}
46
- flat = {}
80
+ flat = CaseInsensitiveHeaders.new
47
81
  raw_headers.each do |name, value|
48
82
  key = name.to_s.downcase
49
83
  values = value.is_a?(Array) ? value.map(&:to_s) : value.to_s.split("\n")
@@ -97,6 +131,16 @@ module Tina4
97
131
  def initialize(app = nil, root_dir: nil)
98
132
  @app = app
99
133
  @root_dir = root_dir
134
+
135
+ # #296: load .env the way the server does, so a TestClient test that never
136
+ # booted the app still sees TINA4_SECRET etc. load_env is first-wins
137
+ # (ENV[key] ||= value, .env.local then .env), so a value the test set in
138
+ # the real environment is never clobbered — the test still wins.
139
+ begin
140
+ Tina4::Env.load_env(@root_dir || Tina4.root_dir || Dir.pwd)
141
+ rescue StandardError
142
+ # A missing or unreadable .env must never stop a test from running.
143
+ end
100
144
  end
101
145
 
102
146
  def app
data/lib/tina4/version.rb CHANGED
@@ -7,5 +7,5 @@
7
7
 
8
8
 
9
9
  module Tina4
10
- VERSION = "3.13.160"
10
+ VERSION = "3.13.162"
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.160
4
+ version: 3.13.162
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-07 00:00:00.000000000 Z
11
+ date: 2026-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3