Skip to content

Add Client#ping(timeout:) for FreeTDS-bounded liveness checks - #609

Open
emailrhoads wants to merge 1 commit into
rails-sqlserver:masterfrom
emailrhoads:add-client-ping-timeout
Open

emailrhoads wants to merge 1 commit into
rails-sqlserver:masterfrom
emailrhoads:add-client-ping-timeout

Conversation

@emailrhoads

@emailrhoads emailrhoads commented Sep 16, 2026

Copy link
Copy Markdown

Summary

  • Adds TinyTds::Client#ping(timeout:) that temporarily sets FreeTDS DBSETTIME, runs SELECT 1, restores the previous timeout on success, and returns false on timeout/failure so callers can discard the handle.
  • Adds query_timeout / query_timeout= (shared helper also used at connect) so a live client can change query timeout without reconnecting.
  • Does not change passive active? / dead? (dbdead) — explicit #ping keeps the opt-in clear for adapters/apps.

This is meant as the driver-level answer to the checkout-liveness question in activerecord-sqlserver-adapter#1396: idle TCP RST (TCP reset — peer or middlebox abruptly closes the socket while the client still believes the session is alive) plus passive FreeTDS dbdead. Ruby Timeout around execute does not reliably interrupt TinyTDS/C I/O; the short bound has to be FreeTDS-level. Policy for when to call #ping (e.g. adapter verify! / active?) can live in the adapter — see follow-up activerecord-sqlserver-adapter#1412.

Test plan

  • bundle exec rake compile
  • test/client_test.rb: query_timeout from connect; query_timeout= bounds WaitFor; #ping returns true and restores timeout; #ping returns false when round-trip exceeds ping timeout; ArgumentError / closed client cases

Temporarily lower DBSETTIME for SELECT 1 so dead/idle-RST handles fail in
seconds instead of the connection's long query timeout; restore on success.
Returns false on failure so callers can discard the client.

Addresses the liveness-probe discussion in
rails-sqlserver/activerecord-sqlserver-adapter#1396 without changing passive
active?/dead? semantics.

Co-authored-by: Cursor <cursoragent@cursor.com>
@emailrhoads

Copy link
Copy Markdown
Author

Tracking discussion / attention request on the adapter side: rails-sqlserver/activerecord-sqlserver-adapter#1413 (also links this PR and adapter #1412).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant