Browse Source

Check handshake status, ignoring bit 16#4000, SERVER_SESSION_STATE_CHANGED

Feng Lee 7 years ago
parent
commit
d8fe39337d
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/mysql_protocol.erl

+ 4 - 4
src/mysql_protocol.erl

@@ -67,13 +67,13 @@ handshake(Username, Password, Database, SockModule0, SSLOpts, Socket0,
     handshake_finish_or_switch_auth(Handshake, Password, SockModule, Socket,
     handshake_finish_or_switch_auth(Handshake, Password, SockModule, Socket,
                                     SeqNum3).
                                     SeqNum3).
 
 
-handshake_finish_or_switch_auth(Handshake, Password, SockModule, Socket,
-                                SeqNum0) ->
+handshake_finish_or_switch_auth(Handshake = #handshake{status = Status}, Password,
+                                SockModule, Socket, SeqNum0) ->
     {ok, ConfirmPacket, SeqNum1} = recv_packet(SockModule, Socket, SeqNum0),
     {ok, ConfirmPacket, SeqNum1} = recv_packet(SockModule, Socket, SeqNum0),
     case parse_handshake_confirm(ConfirmPacket) of
     case parse_handshake_confirm(ConfirmPacket) of
         #ok{status = OkStatus} ->
         #ok{status = OkStatus} ->
-            true = (OkStatus == Handshake#handshake.status)
-                    orelse (OkStatus == (16#4000 bor Handshake#handshake.status)),
+            %% check status, ignoring bit 16#4000, SERVER_SESSION_STATE_CHANGED.
+            Status = OkStatus band bnot 16#4000,
             {ok, Handshake, SockModule, Socket};
             {ok, Handshake, SockModule, Socket};
         #auth_method_switch{auth_plugin_name = AuthPluginName,
         #auth_method_switch{auth_plugin_name = AuthPluginName,
                             auth_plugin_data = AuthPluginData} ->
                             auth_plugin_data = AuthPluginData} ->