From bbfbf53cd8f14527d61ff24da3c892502998c9e5 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 3 Sep 2021 15:35:36 +0000 Subject: [PATCH] additional handling of ER_CONNECTION_KILLED in mar.c --- hio/lib/err.c | 2 +- hio/lib/hio.h | 2 +- hio/lib/mar-cli.c | 2 +- hio/lib/mar.c | 24 ++++++++++++++++-------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/hio/lib/err.c b/hio/lib/err.c index 2e813aa..2ef28e4 100644 --- a/hio/lib/err.c +++ b/hio/lib/err.c @@ -49,7 +49,7 @@ static hio_ooch_t errstr_20[] = {'I', '/', 'O', ' ', 'e', 'r', 'r', 'o', 'r', '\ static hio_ooch_t errstr_21[] = {'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 's', 'i', 'o', 'n', ' ', 'e', 'r', 'r', 'o', 'r', '\0' }; static hio_ooch_t errstr_22[] = {'i', 'n', 's', 'u', 'f', 'f', 'i', 'c', 'i', 'e', 'n', 't', ' ', 'd', 'a', 't', 'a', ' ', 'f', 'o', 'r', ' ', 'e', 'n', 'c', 'o', 'd', 'i', 'n', 'g', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 's', 'i', 'o', 'n', '\0' }; static hio_ooch_t errstr_23[] = {'b', 'u', 'f', 'f', 'e', 'r', ' ', 'f', 'u', 'l', 'l', '\0' }; -static hio_ooch_t errstr_24[] = {'n', 'o', 't', ' ', 'c', 'o', 'n', 'n', 'e', 'c', 't', 'e', 'd', '\0' }; +static hio_ooch_t errstr_24[] = {'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'l', 'o', 's', 't', '\0' }; static hio_ooch_t errstr_25[] = {'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'r', 'e', 'f', 'u', 's', 'e', 'd', '\0' }; static hio_ooch_t errstr_26[] = {'c', 'o', 'n', 'n', 'e', 'c', 't', 'i', 'o', 'n', ' ', 'r', 'e', 's', 'e', 't', '\0' }; static hio_ooch_t errstr_27[] = {'n', 'o', ' ', 'c', 'a', 'p', 'a', 'b', 'i', 'l', 'i', 't', 'y', '\0' }; diff --git a/hio/lib/hio.h b/hio/lib/hio.h index 50d5642..af2a9cc 100644 --- a/hio/lib/hio.h +++ b/hio/lib/hio.h @@ -99,7 +99,7 @@ enum hio_errnum_t HIO_EECMORE, /**< insufficient data for encoding conversion */ HIO_EBUFFULL, /**< buffer full */ - HIO_ENOTCON, /**< not connected */ + HIO_ECONLOST, /**< connection lost */ HIO_ECONRF, /**< connection refused */ HIO_ECONRS, /**< connection reset */ HIO_ENOCAPA, /**< no capability */ diff --git a/hio/lib/mar-cli.c b/hio/lib/mar-cli.c index 1c9cf0e..47f126e 100644 --- a/hio/lib/mar-cli.c +++ b/hio/lib/mar-cli.c @@ -577,7 +577,7 @@ int hio_svc_marc_querywithbchars (hio_svc_marc_t* marc, hio_oow_t flagged_sid, h return -1; } - /* the underlying socket of the device may get disconnected. + /* the underlying socket of the device might have gotten disconnected. * in such a case, keep the enqueued query with sq->sent 0 * and defer actual sending and processing */ } diff --git a/hio/lib/mar.c b/hio/lib/mar.c index bea5ebf..8fb5ae1 100644 --- a/hio/lib/mar.c +++ b/hio/lib/mar.c @@ -28,13 +28,19 @@ #if 0 #include #include +#include #else #include #include +#include #endif #include +#if !defined(ER_CONNECTION_KILLED) +# define ER_CONNECTION_KILLED (1927) +#endif + /* ========================================================================= */ static int dev_mar_make (hio_dev_t* dev, void* ctx) @@ -296,12 +302,14 @@ static int dev_mar_ioctl (hio_dev_t* dev, int cmd, void* arg) if (err) { /* but there is an error */ - if (err == 1) err = mysql_errno(rdev->hnd); + if (err == 1 || err == -1) err = mysql_errno(rdev->hnd); - hio_seterrbfmt (hio, HIO_ESYSERR, "%hs", mysql_error(rdev->hnd)); - if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR) + hio_seterrbfmt (hio, HIO_ESYSERR, "%hs [code=%d]", mysql_error(rdev->hnd), err); + if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR || err == CR_COMMANDS_OUT_OF_SYNC || err == ER_CONNECTION_KILLED) { - /* the underlying socket must have gotten closed by mysql_real_query_start() */ + /* the underlying socket is closed by the mysql client library when this happens. + * so the mysql_get_socket(rdev->hnd) afterwards is never reliable */ + const hio_ooch_t* prev_errmsg; prev_errmsg = hio_backuperrmsg(hio); @@ -312,7 +320,7 @@ static int dev_mar_ioctl (hio_dev_t* dev, int cmd, void* arg) watch_mysql (rdev, 0); hio_dev_mar_halt (rdev); /* i can't keep this device alive regardless of the caller's post-action */ - hio_seterrbfmt (hio, HIO_ENOTCON, "%js", prev_errmsg); + hio_seterrbfmt (hio, HIO_ECONLOST, "%js", prev_errmsg); } return -1; } @@ -487,14 +495,14 @@ static int dev_evcb_mar_ready (hio_dev_t* dev, int events) if (err) { /* query send failure */ - if (err == 1) err = mysql_errno(rdev->hnd); /* err is set to 1 by mariadb-connector-c 3.1 as of this writing. let me work around it by fetching the error code */ + if (err == 1 || err == -1) err = mysql_errno(rdev->hnd); /* err is set to 1 by mariadb-connector-c 3.1 as of this writing. let me work around it by fetching the error code */ - if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR) + if (err == CR_SERVER_LOST || err == CR_SERVER_GONE_ERROR || err == CR_COMMANDS_OUT_OF_SYNC || err == ER_CONNECTION_KILLED) { /* preserving the error information here isn't very useful because the info won't survive until on_disconnect() is called... - hio_seterrbfmt (hio, HIO_ENOTCON, "%hs", mysql_error(rdev->hnd)); + hio_seterrbfmt (hio, HIO_ECONLOST, "%hs", mysql_error(rdev->hnd)); */ rdev->broken = 1;