bidi2pdf-rails 0.1.8 → 0.1.9

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: 5709c4796138806a0351497dd9b688766b106a7dd382ff940aa6fb9bbe17e979
4
- data.tar.gz: 84d482e9eb3d0ebd32795d9141881ba1f2913aeea73f99abbb91ad6024c1e53f
3
+ metadata.gz: 2332109f64dfa072948f7df7e63171721fa48a5d17c82cdadd12c91ea13d0940
4
+ data.tar.gz: 87ca97dda6e567ad1e44aeae276680969b661337f7c2865e6cbd75fe9e0c9b9e
5
5
  SHA512:
6
- metadata.gz: de670de3d0a443caf7864f7096a77025736be687ea5ced46ec6f828623ce1bfe159e5d95e29a1d8518f94a017b436f5802af8caced23bd058b822494ad594920
7
- data.tar.gz: 95d6daf093a0aa799490f892cf53669435cc384762f815db017fa8928bff1eaadc4c94dad2ad884b40b4e05f934b8e9368ca0b8152cb30435ae9b9b80edb6ce5
6
+ metadata.gz: fb49e86ea6dc866a7b0434a35be016310cdc9e0c213e3198c33375b6c79f0bf59eee0c28f764899202b70e07b77abfcfd02b791a7b4b3f02ecf2fead05a2274b
7
+ data.tar.gz: c0e3608db45453b1f85ede001370edd921b2f61748dfca9b0e76f344d49f5eab9a846cd22e0ffef009d0c1a868b5cdb1595bbece0f0c81410c0be2bd69025105
data/CHANGELOG.md CHANGED
@@ -8,10 +8,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
- [unreleased]: https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.8..HEAD
11
+ [unreleased]: https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.9..HEAD
12
12
 
13
13
  <!-- generated by git-cliff end -->
14
14
 
15
+ ## [0.1.9] - 2026-10-29
16
+
17
+ ### 🐛 Fixed
18
+
19
+ - Wait for the held permit with a barrier by @dieter-medium
20
+ in [#32](https://github.com/dieter-medium/bidi2pdf-rails/pull/32)
21
+
22
+ ### 📝 Docs
23
+
24
+ - Match the session start limit of bidi2pdf 0.1.26 by @dieter-medium
25
+ in [#32](https://github.com/dieter-medium/bidi2pdf-rails/pull/32)
26
+
27
+ ### 🚀 Added
28
+
29
+ - Pass bidi2pdf's session start limit through by @dieter-medium
30
+ in [#32](https://github.com/dieter-medium/bidi2pdf-rails/pull/32)
31
+
32
+ [0.1.9]: https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.8..v0.1.9
33
+
15
34
  ## [0.1.8] - 2026-10-09
16
35
 
17
36
  ### 🐛 Fixed
@@ -173,7 +192,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
173
192
 
174
193
  ### 🔄 Released
175
194
 
176
- - [unreleased](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.8..HEAD)
195
+ - [unreleased](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.9..HEAD)
196
+ - [0.1.9](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.8..v0.1.9)
177
197
  - [0.1.8](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.7..v0.1.8)
178
198
  - [0.1.7](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.6..v0.1.7)
179
199
  - [0.1.6](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.5..v0.1.6)
data/README.md CHANGED
@@ -306,6 +306,24 @@ Requires **bidi2pdf >= 0.1.20**. Settings that came with it:
306
306
  | `session_warmer_settings.size` | `1` | Number of sessions kept warm. |
307
307
  | `session_warmer_settings.max_idle_age` | `300` | Seconds a warm session may sit unused before it is retired and replaced - an idle warm session is an open, unauthenticated automation port. `nil` disables the limit. |
308
308
 
309
+ With **bidi2pdf >= 0.1.26** (ignored by older versions):
310
+
311
+ | Setting | Default | Description |
312
+ |---------------------------------------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
313
+ | `general_options.session_start_concurrency` | `2` | Chrome session setups (session request to first tab) at once in this process; `nil`: no limit. Several setups at the same moment made chromedriver leave setup commands unanswered (bidi2pdf README "Session start limit"). |
314
+ | `general_options.session_start_timeout` | `nil` | Seconds a setup waits for its turn before it fails with `Bidi2pdf::SessionStartTimeoutError`; `nil` uses `default_timeout`. |
315
+
316
+ **The limit holds per process.** Chrome counts the setups of every process that talks to it, so Puma workers and a
317
+ job process sharing one remote chromedriver divide its budget of about two: with a web and a job process, set
318
+ `session_start_concurrency = 1`. With more processes, either give them Chromes of their own, or share one budget
319
+ across them with a gate of your own - set it in `Bidi2pdf.configure` (`config.session_gate`, any object answering
320
+ `with_permit { ... }`, e.g. a file lock all processes can reach; bidi2pdf README "Session start limit").
321
+ Bidi2pdfRails leaves that setting alone.
322
+
323
+ **Set it at boot.** bidi2pdf reads the limit once per process, at its first session setup (and again in a forked
324
+ Puma worker): the initializer is the place. A change after the first render is logged and takes effect after a
325
+ restart.
326
+
309
327
  **`chromedriver_settings.port` is incompatible with the session warmer.** The warmer keeps a
310
328
  replacement chromedriver warming in the background while a checked-out slot's own chromedriver is
311
329
  still running, so at least two chromedrivers are alive at once even at `size = 1` - they cannot share
@@ -20,6 +20,8 @@ module Bidi2pdfRails
20
20
  { name: :notification_service, desc: "Notification service", default: -> { ActiveSupport::Notifications }, default_as_str: "-> { ActiveSupport::Notifications }", ask: false },
21
21
  { name: :default_timeout, desc: "Default timeout for various Bidi commands", default: 10, ask: true, color: :yellow },
22
22
  { name: :log_truncate_limit, desc: "Max bytes of a single logged value (e.g. a data: URL) before it is truncated", default: 200, ask: false, color: :yellow },
23
+ { name: :session_start_concurrency, desc: "Chrome session setups at once in this process (bidi2pdf >= 0.1.26, README \"Session start limit\"); nil: no limit. Processes sharing one Chrome divide its budget of about 2", default: 2, ask: false, color: :yellow },
24
+ { name: :session_start_timeout, desc: "Seconds a session setup waits for its turn (bidi2pdf >= 0.1.26); nil: default_timeout", default: nil, ask: false, color: :yellow },
23
25
  { name: :chrome_session_args, desc: "Chrome session arguments", default: Bidi2pdf::Bidi::Session::DEFAULT_CHROME_ARGS, ask: false }
24
26
  ]
25
27
  },
@@ -36,10 +36,13 @@ module Bidi2pdfRails
36
36
  # closed - a half-started session left in the pooled thread's slot would be reused broken, by
37
37
  # the retry among others.
38
38
  def run_with_chromedriver_manager_singleton
39
- browser = ChromedriverManagerSingleton.session.browser
40
- context = browser.create_user_context
41
- window = context.create_browser_window
42
- tab = window.create_browser_tab
39
+ context = window = tab = nil
40
+ with_session_start_permit do
41
+ browser = ChromedriverManagerSingleton.session.browser
42
+ context = browser.create_user_context
43
+ window = context.create_browser_window
44
+ tab = window.create_browser_tab
45
+ end
43
46
 
44
47
  print_and_notify(tab)
45
48
  ensure
@@ -49,6 +52,13 @@ module Bidi2pdfRails
49
52
  ChromedriverManagerSingleton.session_close
50
53
  end
51
54
 
55
+ # From the session request to the first tab under one turn of bidi2pdf's session start limit
56
+ # (Bidi2pdf::SessionGate, bidi2pdf 0.1.26 and later): several sessions set up at once made
57
+ # chromedriver leave setup commands unanswered. The render after it is not limited.
58
+ def with_session_start_permit(&)
59
+ defined?(Bidi2pdf::SessionGate) ? Bidi2pdf::SessionGate.with_permit(&) : yield
60
+ end
61
+
52
62
  def print_and_notify(tab)
53
63
  prepare_tab(tab)
54
64
  base64_data = tab.print(print_options: @print_options)
@@ -1,3 +1,3 @@
1
1
  module Bidi2pdfRails
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
@@ -36,6 +36,12 @@ module Bidi2pdfRails
36
36
  bidi2pdf_config.log_truncate_limit = config.general_options.log_truncate_limit_value
37
37
  bidi2pdf_config.chromedriver_log_level = config.chromedriver_settings.log_level_value
38
38
 
39
+ # bidi2pdf 0.1.26 and later only: older versions have no session start limit.
40
+ if bidi2pdf_config.respond_to?(:session_start_concurrency=)
41
+ bidi2pdf_config.session_start_concurrency = config.general_options.session_start_concurrency_value
42
+ bidi2pdf_config.session_start_timeout = config.general_options.session_start_timeout_value
43
+ end
44
+
39
45
  bidi2pdf_config.network_events_logger = Logger.new(nil)
40
46
  bidi2pdf_config.browser_console_logger = Logger.new(nil)
41
47
 
@@ -46,4 +46,33 @@ RSpec.describe Bidi2pdfRails do
46
46
  expect(Bidi2pdf.log_truncate_limit).to eq(50)
47
47
  end
48
48
  end
49
+
50
+ # bidi2pdf 0.1.26: the session start limit (README "Session start limit" in bidi2pdf).
51
+ describe ".apply_bidi2pdf_config with the session start limit",
52
+ skip: (Bidi2pdf.respond_to?(:session_start_concurrency=) ? false : "this bidi2pdf has no session start limit (0.1.26 and later)") do
53
+ around do |example|
54
+ options = described_class.config.general_options
55
+ limit = options.session_start_concurrency
56
+ timeout = options.session_start_timeout
57
+ example.run
58
+ ensure
59
+ options.session_start_concurrency = limit
60
+ options.session_start_timeout = timeout
61
+ described_class.apply_bidi2pdf_config
62
+ end
63
+
64
+ it "allows two session setups at once by default, like bidi2pdf" do
65
+ described_class.apply_bidi2pdf_config
66
+
67
+ expect(Bidi2pdf.session_start_concurrency).to eq(2)
68
+ end
69
+
70
+ it "hands general_options.session_start_concurrency and session_start_timeout through to bidi2pdf" do
71
+ described_class.config.general_options.session_start_concurrency = 1
72
+ described_class.config.general_options.session_start_timeout = 5
73
+ described_class.apply_bidi2pdf_config
74
+
75
+ expect([Bidi2pdf.session_start_concurrency, Bidi2pdf.session_start_timeout]).to eq([1, 5])
76
+ end
77
+ end
49
78
  end
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../../../rails_helper"
4
+
5
+ # The path without the session warmer sets its session up - request to first tab - under one turn of bidi2pdf's
6
+ # session start limit (Bidi2pdf::SessionGate, bidi2pdf 0.1.26).
7
+ RSpec.describe Bidi2pdfRails::Services::PdfBrowserSession,
8
+ skip: (defined?(Bidi2pdf::SessionGate) ? false : "this bidi2pdf has no session start limit (0.1.26 and later)") do
9
+ let(:tab) { instance_double(Bidi2pdf::Bidi::BrowserTab, close: nil) }
10
+ let(:window) { instance_double(Bidi2pdf::Bidi::BrowserTab, create_browser_tab: tab, close: nil) }
11
+ let(:context) { instance_double(Bidi2pdf::Bidi::UserContext, create_browser_window: window, close: nil) }
12
+ let(:browser) { instance_double(Bidi2pdf::Bidi::Browser, create_user_context: context) }
13
+ let(:session) { instance_double(Bidi2pdf::Bidi::Session, browser: browser) }
14
+
15
+ let(:renderer) do
16
+ Class.new do
17
+ include Bidi2pdfRails::Services::PdfBrowserSession
18
+
19
+ def render = run_with_chromedriver_manager_singleton
20
+
21
+ def print_and_notify(_tab) = :printed
22
+ end.new
23
+ end
24
+
25
+ before do
26
+ allow(Bidi2pdfRails::ChromedriverManagerSingleton).to receive_messages(session: session, session_close: nil)
27
+ end
28
+
29
+ around do |example|
30
+ limit = Bidi2pdf.session_start_concurrency
31
+ timeout = Bidi2pdf.session_start_timeout
32
+ Bidi2pdf.session_start_concurrency = 1
33
+ Bidi2pdf.session_start_timeout = 0.1
34
+ Bidi2pdf::SessionGate.reset!
35
+ example.run
36
+ ensure
37
+ Bidi2pdf.session_start_concurrency = limit
38
+ Bidi2pdf.session_start_timeout = timeout
39
+ Bidi2pdf::SessionGate.reset!
40
+ end
41
+
42
+ it "renders when a permit is free" do
43
+ expect(renderer.render).to eq(:printed)
44
+ end
45
+
46
+ # Holds the only permit until the block is done - the holder says when it has it, so the render cannot get there
47
+ # first (a sleep could not promise that under CI load; review of PR #32).
48
+ def while_every_permit_is_taken
49
+ held = Thread::Queue.new
50
+ done = Thread::Queue.new
51
+ holder = Thread.new do
52
+ Bidi2pdf::SessionGate.with_permit do
53
+ held << true
54
+ done.pop
55
+ end
56
+ end
57
+ held.pop
58
+ yield
59
+ ensure
60
+ done << true
61
+ holder&.join
62
+ end
63
+
64
+ it "fails with SessionStartTimeoutError while every permit is taken" do
65
+ while_every_permit_is_taken do
66
+ expect { renderer.render }.to raise_error(Bidi2pdf::SessionStartTimeoutError)
67
+ end
68
+ end
69
+
70
+ it "opens no tab while every permit is taken" do
71
+ while_every_permit_is_taken do
72
+ renderer.render
73
+ rescue Bidi2pdf::SessionStartTimeoutError
74
+ nil
75
+ end
76
+
77
+ expect(browser).not_to have_received(:create_user_context)
78
+ end
79
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidi2pdf-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter S.
@@ -480,6 +480,7 @@ files:
480
480
  - spec/unit/bidi2pdf_rails/chrome_sweeping_spec.rb
481
481
  - spec/unit/bidi2pdf_rails/chromedriver_manager_singleton_spec.rb
482
482
  - spec/unit/bidi2pdf_rails/configurable/base_nested_config_spec.rb
483
+ - spec/unit/bidi2pdf_rails/services/pdf_browser_session_spec.rb
483
484
  - tasks/bidi2pdf_rails_tasks.rake
484
485
  - tasks/changelog.rake
485
486
  - tasks/coverage.rake
@@ -742,3 +743,4 @@ test_files:
742
743
  - spec/unit/bidi2pdf_rails/chrome_sweeping_spec.rb
743
744
  - spec/unit/bidi2pdf_rails/chromedriver_manager_singleton_spec.rb
744
745
  - spec/unit/bidi2pdf_rails/configurable/base_nested_config_spec.rb
746
+ - spec/unit/bidi2pdf_rails/services/pdf_browser_session_spec.rb