Skip to content

fix(client): re-send session configuration on reconnect - #178

Open
taka-2628 wants to merge 1 commit into
apache:mainfrom
taka-2628:fix/reconnect-session-configuration
Open

fix(client): re-send session configuration on reconnect#178
taka-2628 wants to merge 1 commit into
apache:mainfrom
taka-2628:fix/reconnect-session-configuration

Conversation

@taka-2628

Copy link
Copy Markdown

Description

Session.initClusterConn() builds its TSOpenSessionReq without a Configuration map, while Session.Open() and Session.OpenCluster() both populate Configuration["sql_dialect"], ["version"], and ["db"]. Since reconnect() — the sole transparent-reconnect path, invoked from every insert/query/execute method on a transport error — routes exclusively through initClusterConn(), any session that reconnects after a server restart silently reverts to the server-default dialect with no database bound.

For table-model sessions this poisons the session: every subsequent statement is rejected with a SqlParseError (700) / SemanticError (701). Because these are valid server responses (*ExecutionError) rather than Go transport errors, TableSessionPool.isConnectionError returns false for them and the poisoned session is returned to the pool until the process restarts. The reference Java client re-sends this configuration on reconnect (SessionConnection.init() via reconnect()); the Go client did not.

Full analysis, including the diagnosis path and the pool-poisoning mechanism, in #177.

This bug exists because the same request-configuration block was hand-duplicated across three open paths and one copy was missed. This change extracts a single helper, buildOpenSessionConfiguration, and wires all three sites (Open, OpenCluster, initClusterConn) through it so they cannot drift again.

s.config already carries sqlDialect/Database at reconnect time. Cluster sessions carry no Version (ClusterConfig has no such field), so for them the empty-VersionDEFAULT_VERSION fallback reproduces exactly what OpenCluster() already sends.

Verification

  • Reproduced and fixed against a live server. apache/iotdb:2.0.3-standalone with a TableSessionPool bound to a database: insert (succeeds) → docker restart the server → insert again on the reconnected pooled session. On the current code the post-restart insert fails with error code: 700 ... mismatched input 't' expecting ROOT (session reverted to tree dialect); with this change the post-restart insert succeeds. Same test, only the library changed.
  • Added TestBuildOpenSessionConfiguration (table-driven, matching the existing session_test.go style). go build ./..., go vet ./client/, and go test ./client/ pass.

Out of scope (noted for maintainers)

initClusterConn also never sets s.timeFactor via getTimeFactor(resp), which Open/OpenCluster do — a reconnected session keeps a stale timeFactor. Benign on homogeneous clusters; happy to fold it into this PR if preferred.

Fixes #177

Session.initClusterConn() built its TSOpenSessionReq without a
Configuration map, while Open() and OpenCluster() populate
Configuration["sql_dialect"], ["version"], and ["db"]. Because
reconnect() routes exclusively through initClusterConn() and is the sole
transparent-reconnect path, any session that reconnects after a server
restart silently reverted to the server-default dialect with no database
bound. For table-model sessions this poisons the session: every
subsequent statement fails with a SqlParseError (700), and because that
is a valid server response rather than a transport error, TableSessionPool
keeps the session in the pool.

Extract the Configuration-building block into a single helper and call it
from all three open paths so the reconnect path sends what open sends and
the three cannot drift again. Add a table-driven test for the helper.

Verified against apache/iotdb:2.0.3-standalone: a table-model insert on a
pooled session that reconnects after `docker restart` fails on the current
code and succeeds with this change.

Fixes apache#177

Co-Authored-By: Claude <noreply@anthropic.com>
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.

Session.reconnect() drops session Configuration (sql_dialect, db, version); sessions silently revert to server defaults after a server restart

1 participant