whatyouhide/xandra

`WithClauseError` while decoding frame in protocol v5

Closed this issue · 1 comments

When using protocol v5, we had (extremely rare, occured a couple of times within same 5 mins) errors like the followings:

 ** (exit) an exception was raised:
     ** (DBConnection.ConnectionError) client #PID<0.1035.1> stopped: ** (WithClauseError) no with clause matching: {:ok, <<133, 0, 0, 0, 8, 0, 1, 255, 236, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 8, 0, 0, 7, 135, 0, 0, 0, 4, 0, 0, 195, 167, 0, 0, 0, 4, 0, 0, 0, 198, 0, 0, 0, 4, 0, 0, 0, ...>>}
     (xandra 0.15.0) lib/xandra/connection.ex:312: Xandra.Connection.send_query/4
     (xandra 0.15.0) lib/xandra/connection.ex:295: anonymous fn/5 in Xandra.Connection.handle_execute/4
     (telemetry 1.0.0) /builds/vpp/vpp/deps/telemetry/src/telemetry.erl:293: :telemetry.span/3
     (db_connection 2.5.0) lib/db_connection/holder.ex:354: DBConnection.Holder.holder_apply/4
     (db_connection 2.5.0) lib/db_connection.ex:1432: DBConnection.run_execute/5
     (db_connection 2.5.0) lib/db_connection.ex:713: DBConnection.execute/4
     (xandra 0.15.0) lib/xandra.ex:1275: anonymous fn/4 in Xandra.execute_without_retrying/4
     (db_connection 2.5.0) lib/db_connection.ex:843: DBConnection.run/3
         (db_connection 2.5.0) lib/db_connection/connection.ex:203: DBConnection.Connection.handle_event/4
         (stdlib 4.2) gen_statem.erl:1428: :gen_statem.loop_state_callback/11
         (stdlib 4.2) proc_lib.erl:250: :proc_lib.wake_up/3

looking at the binary, it looks like a legit Frame, I'm not sure why we're getting the raw binary in that with statement. Following works (payload body length limited to 20):

alias Xandra.Frame
payload = <<133, 0, 0, 0, 8, 0, 0, 0, 20, 0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 8, 0, 0, 7, 135, 0, 0, 0, 4, 0, 0, 195, 167, 0, 0, 0, 4, 0, 0, 0, 198, 0, 0, 0, 4, 0, 0, 0>>
Frame.decode_from_binary(payload, nil)
{%Xandra.Frame{
   kind: :result,
   body: <<0, 0, 0, 2, 0, 0, 0, 5, 0, 0, 0, 8, 0, 0, 7, 135, 0, 0, 0, 4>>,
   protocol_version: :v5,
   stream_id: 0,
   compressor: nil,
   tracing: false,
   warning: false,
   custom_payload: false,
   use_beta: false,
   atom_keys?: false
 }, <<0, 0, 195, 167, 0, 0, 0, 4, 0, 0, 0, 198, 0, 0, 0, 4, 0, 0, 0>>}

@harunzengin should not happen anymore ☝️ 😉