Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-15 08:37:47

0001 //
0002 // Copyright (c) 2019-2024 Ruben Perez Hidalgo (rubenperez038 at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 
0008 #ifndef BOOST_MYSQL_IMPL_IS_FATAL_ERROR_IPP
0009 #define BOOST_MYSQL_IMPL_IS_FATAL_ERROR_IPP
0010 
0011 #pragma once
0012 
0013 #include <boost/mysql/client_errc.hpp>
0014 #include <boost/mysql/common_server_errc.hpp>
0015 #include <boost/mysql/error_categories.hpp>
0016 #include <boost/mysql/is_fatal_error.hpp>
0017 
0018 bool boost::mysql::is_fatal_error(error_code ec) noexcept
0019 {
0020     // If there is no failure, it's not fatal
0021     if (!ec)
0022         return false;
0023 
0024     // Retrieve the error category
0025     const auto& cat = ec.category();
0026 
0027     if (cat == get_common_server_category())
0028     {
0029         // Server errors may or may not be fatal. MySQL defines a ton of different errors.
0030         // After some research, these are the ones I'd recommend to consider fatal
0031         auto code = static_cast<common_server_errc>(ec.value());
0032         switch (code)
0033         {
0034         // Different flavors of communication errors. These usually indicate that the connection
0035         // has been left in an unspecified state, and the safest is to reconnect it.
0036         case common_server_errc::er_unknown_com_error:
0037         case common_server_errc::er_aborting_connection:
0038         case common_server_errc::er_net_packet_too_large:
0039         case common_server_errc::er_net_read_error_from_pipe:
0040         case common_server_errc::er_net_fcntl_error:
0041         case common_server_errc::er_net_packets_out_of_order:
0042         case common_server_errc::er_net_uncompress_error:
0043         case common_server_errc::er_net_read_error:
0044         case common_server_errc::er_net_read_interrupted:
0045         case common_server_errc::er_net_error_on_write:
0046         case common_server_errc::er_net_write_interrupted:
0047         case common_server_errc::er_malformed_packet:
0048         case common_server_errc::er_zlib_z_buf_error:
0049         case common_server_errc::er_zlib_z_data_error:
0050         case common_server_errc::er_zlib_z_mem_error: return true;
0051         default: return false;
0052         }
0053     }
0054     else if (cat == get_mysql_server_category() || cat == get_mariadb_server_category())
0055     {
0056         // DB-specific codes are all non fatal
0057         return false;
0058     }
0059     else if (cat == get_client_category())
0060     {
0061         auto code = static_cast<client_errc>(ec.value());
0062         switch (code)
0063         {
0064         // These indicate malformed frames or packet mismatches
0065         case client_errc::incomplete_message:
0066         case client_errc::protocol_value_error:
0067         case client_errc::extra_bytes:
0068         case client_errc::sequence_number_mismatch:
0069 
0070         // Exceeding the max buffer size is not recoverable
0071         case client_errc::max_buffer_size_exceeded:
0072 
0073         // These are produced by the static interface, and currently cause parsing
0074         // to stop, leaving unread packets in the network buffer.
0075         // See https://github.com/boostorg/mysql/issues/212
0076         case client_errc::metadata_check_failed:
0077         case client_errc::num_resultsets_mismatch:
0078         case client_errc::row_type_mismatch:
0079         case client_errc::static_row_parsing_error:
0080 
0081         // While these are currently produced only by the connection pool,
0082         // any timed out or cancelled operation would leave the connection in an undefined state
0083         case client_errc::timeout:
0084         case client_errc::cancelled:
0085 
0086         // These are only produced by handshake. We categorize them as fatal because they need reconnection,
0087         // although anything affecting handshake effectively does.
0088         case client_errc::server_doesnt_support_ssl:
0089         case client_errc::unknown_auth_plugin:
0090         case client_errc::server_unsupported:
0091         case client_errc::auth_plugin_requires_ssl: return true;
0092 
0093         default: return false;
0094         }
0095     }
0096     else
0097     {
0098         // Other categories are fatal - these include network and SSL errors
0099         return true;
0100     }
0101 }
0102 
0103 #endif