Skip to content

fix(Cluster): pass seconds, not milliseconds, for heartbeat and TCP keepalive - #145

Open
CodeLieutenant wants to merge 1 commit into
trunkfrom
claude/blissful-turing-cb4171
Open

fix(Cluster): pass seconds, not milliseconds, for heartbeat and TCP keepalive#145
CodeLieutenant wants to merge 1 commit into
trunkfrom
claude/blissful-turing-cb4171

Conversation

@CodeLieutenant

Copy link
Copy Markdown
Member

Problem

withConnectionHeartbeatInterval() and withTCPKeepalive() converted their argument from seconds to milliseconds. The two cpp-driver functions behind them take seconds:

/* cassandra.h:2530 */
cass_cluster_set_tcp_keepalive(CassCluster*, cass_bool_t enabled, unsigned delay_secs);
/* cassandra.h:2568 */
cass_cluster_set_connection_heartbeat_interval(CassCluster*, unsigned interval_secs);

This is a 1000x error. withConnectionHeartbeatInterval(30.0) sent 30000 seconds, about 8.3 hours, which disabled heartbeats. Dead connections then stayed in the pool until a request failed on them.

The defaults in php_scylladb_cluster_builder_new are raw seconds (connection_heartbeat_interval = 30), so seconds was always the intended unit. Only the setters were wrong.

Changes

  • src/Cluster/Builder.c — add php_scylladb_set_interval_seconds() next to the existing millisecond helper. withConnectionHeartbeatInterval uses it.
  • src/Cluster/Builder.cwithTCPKeepalive stores ceil(delay) instead of ceil(delay * 1000).
  • src/Cluster/BuilderHandlers.cget_properties no longer divides tcpKeepalive by 1000. That divide was the mirror of the same bug, so the property read back the value the user passed in and hid the defect.

The three genuine millisecond settings are untouched: withConnectTimeout, withRequestTimeout, and withReconnectInterval.

Public API

No change. Both methods still take seconds.

Tests

New tests/Unit/Cluster/BuilderTest.php, 13 cases:

  • defaults: connectionHeartbeatInterval is 30, tcpKeepalive is null
  • seconds round-trip through the exposed connectionHeartbeatInterval and tcpKeepalive properties
  • withTCPKeepalive(null) disables keepalive
  • negative values throw Cassandra\Exception\InvalidArgumentException
  • reconnectInterval as a control, because it stays in milliseconds internally

Full unit suite on PHP 8.5 NTS: 816 passed. One pre-existing failure in tests/Unit/Uuid/UuidTest.php:112, a cross-process child-spawn quirk that is unrelated to this change.

Note for the reviewer

Both methods take float but now truncate to whole seconds through ceil, so 0.5 becomes 1. That matches the C API, which has no sub-second granularity, but the PHP signature still advertises precision it cannot deliver. Changing the stub to int is a BC break and belongs in a separate decision.

…eepalive

withConnectionHeartbeatInterval and withTCPKeepalive shared the
seconds-to-milliseconds helper used by the timeout setters. The two
cpp-driver functions behind them take seconds:

  cass_cluster_set_connection_heartbeat_interval(cluster, interval_secs)
  cass_cluster_set_tcp_keepalive(cluster, enabled, delay_secs)

The result was a 1000x error. withConnectionHeartbeatInterval(30.0) sent
30000 seconds, about 8.3 hours, which disabled heartbeats. The defaults in
php_scylladb_cluster_builder_new are raw seconds, so seconds was always the
intended unit.

Add php_scylladb_set_interval_seconds for the two settings that need
seconds, and store the TCP keepalive delay in seconds. get_properties no
longer divides tcpKeepalive by 1000, because the field is now seconds.

The public PHP API does not change. Both methods still take seconds.

Add tests/Unit/Cluster/BuilderTest.php. It checks the defaults, the
seconds round-trip through the exposed connectionHeartbeatInterval and
tcpKeepalive properties, the null case that disables keepalive, and the
rejection of negative values. reconnectInterval is included as a control,
because it stays in milliseconds internally.
@mergify

mergify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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