This is an automated email from the ASF dual-hosted git repository.
jameshartig pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-gocql-driver.git
The following commit(s) were added to refs/heads/trunk by this push:
new 1920205f fix protocol negotiation error handling
1920205f is described below
commit 1920205fb35b22222b468d55f0f2aa017e976188
Author: James Hartig <[email protected]>
AuthorDate: Mon Jun 22 17:40:20 2026 +0000
fix protocol negotiation error handling
In CASSGO-97 and #1920 the handling was changed to better support non-zero
stream id
error responses. But because of hardcoding of version 5 in the test harness
there was
a regression where older protocol responses were not supported anymore.
By adding an Unwrap method to ErrProtocol now the existing checking in
checkProtocolRelatedError will correctly catch the protocolError.
Patch by James Hartig; reviewed by Bohdan Siryk for CASSGO-131
---
CHANGELOG.md | 3 +++
conn_test.go | 7 ++++++-
protocol_negotiation_test.go | 11 ++++++++++-
session.go | 4 ++++
4 files changed, 23 insertions(+), 2 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e34ac1d..cde64a03 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,9 @@ and this project adheres to [Semantic
Versioning](https://semver.org/spec/v2.0.0
- Improve host_source locking and ring refresh concurrency (CASSGO-121)
- Add PreparedMetadata (Keyspace, Table) and IsPrepared fields to
ObservedQuery, and parallel PreparedMetadata / IsPrepared slices to
ObservedBatch, for statement-level observability without CQL parsing
(CASSGO-119)
+### Fixed
+- Correct protocol negotiation with non-Cassandra servers (CASSGO-131)
+
## [2.1.2]
### Fixed
diff --git a/conn_test.go b/conn_test.go
index abc659b5..1cb5ee3f 100644
--- a/conn_test.go
+++ b/conn_test.go
@@ -1259,7 +1259,12 @@ func (srv *TestServer) process(conn net.Conn, reqFrame
*framer, useProtoV5, star
srv.errorLocked("process frame with a nil header")
return
}
- respFrame := newFramer(nil, byte(head.version), GlobalTypes)
+ // use the configured version unless it wasn't specified
+ version := srv.protocol
+ if version == 0 {
+ version = byte(head.version)
+ }
+ respFrame := newFramer(nil, version, GlobalTypes)
if srv.customRequestHandler != nil {
if err := srv.customRequestHandler(srv, reqFrame, respFrame);
err != nil {
diff --git a/protocol_negotiation_test.go b/protocol_negotiation_test.go
index 567c74e3..e58ec1dd 100644
--- a/protocol_negotiation_test.go
+++ b/protocol_negotiation_test.go
@@ -231,9 +231,18 @@ func TestProtocolNegotiation(t *testing.T) {
forceZeroStreamID: tc.forceZeroStreamID,
}
+ // use the maximum protocol supported
+ protocol := uint8(0)
+ for _, supportedVersion := range tc.supportedVersions {
+ supportedProto := uint8(supportedVersion)
+ if supportedProto > protocol {
+ protocol = supportedProto
+ }
+ }
+
srv := newTestServerOpts{
addr: "127.0.0.1:0",
- protocol: 5,
+ protocol: protocol,
customRequestHandler: handler.handle,
dontFailOnProtocolMismatch: true,
}.newServer(t, context.Background())
diff --git a/session.go b/session.go
index dee2a8fe..4717d95c 100644
--- a/session.go
+++ b/session.go
@@ -2532,6 +2532,10 @@ var (
// ErrProtocol represents a protocol-level error.
type ErrProtocol struct{ error }
+func (e ErrProtocol) Unwrap() error {
+ return e.error
+}
+
// NewErrProtocol creates a new protocol error with the specified format and
arguments.
func NewErrProtocol(format string, args ...interface{}) error {
return ErrProtocol{fmt.Errorf(format, args...)}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]