@@ -793,6 +793,7 @@ static ulong my_real_read(NET *net, size_t *complen,
793
793
size_t length;
794
794
uint i,retry_count=0 ;
795
795
ulong len=packet_error;
796
+ my_bool expect_error_packet __attribute__ ((unused))= 0 ;
796
797
retry:
797
798
798
799
uint32 remain= (net->compress ? NET_HEADER_SIZE+COMP_HEADER_SIZE :
@@ -863,7 +864,31 @@ static ulong my_real_read(NET *net, size_t *complen,
863
864
#endif
864
865
if (net->buff [net->where_b + 3 ] != (uchar) net->pkt_nr )
865
866
{
866
- goto packets_out_of_order;
867
+ if (net->pkt_nr_can_be_reset )
868
+ {
869
+ /*
870
+ We are using a protocol like semi-sync where master and slave
871
+ sends packets in parallel.
872
+ Copy current one as it can be useful for debugging.
873
+ */
874
+ net->pkt_nr = net->buff [net->where_b + 3 ];
875
+ }
876
+ else
877
+ {
878
+ #ifndef MYSQL_SERVER
879
+ if (net->buff [net->where_b + 3 ] == (uchar) (net->pkt_nr -1 ))
880
+ {
881
+ /*
882
+ If the server was killed then the server may have missed the
883
+ last sent client packet and the packet numbering may be one off.
884
+ */
885
+ DBUG_PRINT (" warning" , (" Found possible out of order packets" ));
886
+ expect_error_packet= 1 ;
887
+ }
888
+ else
889
+ #endif
890
+ goto packets_out_of_order;
891
+ }
867
892
}
868
893
net->compress_pkt_nr = ++net->pkt_nr ;
869
894
#ifdef HAVE_COMPRESS
@@ -906,6 +931,21 @@ static ulong my_real_read(NET *net, size_t *complen,
906
931
server_extension= NULL ;
907
932
}
908
933
}
934
+ #ifndef MYSQL_SERVER
935
+ else if (expect_error_packet)
936
+ {
937
+ /*
938
+ This check is safe both for compressed and not compressed protocol
939
+ as for the compressed protocol errors are not compressed anymore.
940
+ */
941
+ if (net->buff [net->where_b ] != (uchar) 255 )
942
+ {
943
+ /* Restore pkt_nr to original value */
944
+ net->pkt_nr --;
945
+ goto packets_out_of_order;
946
+ }
947
+ }
948
+ #endif
909
949
}
910
950
911
951
end:
0 commit comments