From eb0432b7b237613a5fd9f2dc873669a70365fd0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 6 Mar 2020 13:56:42 +0200 Subject: [PATCH] MXS-2860: Extract socket error only when needed As the process of extracting the socket error also resets it, it should be done only when necessary. --- server/core/dcb.cc | 56 ++----------------- .../MySQL/mariadbbackend/mysql_backend.cc | 30 ++-------- 2 files changed, 10 insertions(+), 76 deletions(-) diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 005d65c27..e4cf16e09 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -2657,30 +2657,12 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events) if ((events & EPOLLOUT) && (dcb->n_close == 0)) { - int eno = 0; - eno = gw_getsockerrno(dcb->fd); + rc |= MXB_POLL_WRITE; - if (eno == 0) + if (dcb_session_check(dcb, "write_ready")) { - rc |= MXB_POLL_WRITE; - - if (dcb_session_check(dcb, "write_ready")) - { - DCB_EH_NOTICE("Calling dcb->func.write_ready(%p)", dcb); - dcb->func.write_ready(dcb); - } - } - else - { - char errbuf[MXS_STRERROR_BUFLEN]; - MXS_DEBUG("%lu [poll_waitevents] " - "EPOLLOUT due %d, %s. " - "dcb %p, fd %i", - pthread_self(), - eno, - strerror_r(eno, errbuf, sizeof(errbuf)), - dcb, - dcb->fd); + DCB_EH_NOTICE("Calling dcb->func.write_ready(%p)", dcb); + dcb->func.write_ready(dcb); } } if ((events & EPOLLIN) && (dcb->n_close == 0)) @@ -2712,16 +2694,6 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events) } if ((events & EPOLLERR) && (dcb->n_close == 0)) { - int eno = gw_getsockerrno(dcb->fd); - if (eno != 0) - { - char errbuf[MXS_STRERROR_BUFLEN]; - MXS_DEBUG("%lu [poll_waitevents] " - "EPOLLERR due %d, %s.", - pthread_self(), - eno, - strerror_r(eno, errbuf, sizeof(errbuf))); - } rc |= MXB_POLL_ERROR; if (dcb_session_check(dcb, "error")) @@ -2733,16 +2705,6 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events) if ((events & EPOLLHUP) && (dcb->n_close == 0)) { - MXB_AT_DEBUG(int eno = gw_getsockerrno(dcb->fd)); - MXB_AT_DEBUG(char errbuf[MXS_STRERROR_BUFLEN]); - MXS_DEBUG("%lu [poll_waitevents] " - "EPOLLHUP on dcb %p, fd %d. " - "Errno %d, %s.", - pthread_self(), - dcb, - dcb->fd, - eno, - strerror_r(eno, errbuf, sizeof(errbuf))); rc |= MXB_POLL_HUP; if (!dcb->dcb_errhandle_called) @@ -2760,16 +2722,6 @@ static uint32_t dcb_process_poll_events(DCB* dcb, uint32_t events) #ifdef EPOLLRDHUP if ((events & EPOLLRDHUP) && (dcb->n_close == 0)) { - MXB_AT_DEBUG(int eno = gw_getsockerrno(dcb->fd)); - MXB_AT_DEBUG(char errbuf[MXS_STRERROR_BUFLEN]); - MXS_DEBUG("%lu [poll_waitevents] " - "EPOLLRDHUP on dcb %p, fd %d. " - "Errno %d, %s.", - pthread_self(), - dcb, - dcb->fd, - eno, - strerror_r(eno, errbuf, sizeof(errbuf))); rc |= MXB_POLL_HUP; if (!dcb->dcb_errhandle_called) diff --git a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc index 36b8b0435..5be7b58d5 100644 --- a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc +++ b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.cc @@ -1329,29 +1329,15 @@ static int gw_error_backend_event(DCB* dcb) if (dcb->persistentstart == 0) { /** Not a persistent connection, something is wrong. */ - MXS_ERROR("EPOLLERR event on a non-persistent DCB with no session. " - "Closing connection."); + MXS_ERROR("EPOLLERR event on a non-persistent DCB with no session. Closing connection."); } dcb_close(dcb); } else if (dcb->state != DCB_STATE_POLLING || session->state != SESSION_STATE_STARTED) { - int error; - int len = sizeof(error); - - if (getsockopt(dcb->fd, SOL_SOCKET, SO_ERROR, &error, (socklen_t*) &len) == 0 && error != 0) + if (auto err = gw_getsockerrno(dcb->fd)) { - if (dcb->state != DCB_STATE_POLLING) - { - MXS_ERROR("DCB in state %s got error '%s'.", - STRDCBSTATE(dcb->state), - mxs_strerror(errno)); - } - else - { - MXS_ERROR("Error '%s' in session that is not ready for routing.", - mxs_strerror(errno)); - } + MXS_ERROR("DCB in state %s got error '%s'.", STRDCBSTATE(dcb->state), mxs_strerror(err)); } } else @@ -1381,15 +1367,11 @@ static int gw_backend_hangup(DCB* dcb) { if (session->state != SESSION_STATE_STARTED) { - int error; - int len = sizeof(error); - if (getsockopt(dcb->fd, SOL_SOCKET, SO_ERROR, &error, (socklen_t*) &len) == 0) + if (session->state != SESSION_STATE_STOPPING) { - if (error != 0 && session->state != SESSION_STATE_STOPPING) + if (auto err = gw_getsockerrno(dcb->fd)) { - MXS_ERROR("Hangup in session that is not ready for routing, " - "Error reported is '%s'.", - mxs_strerror(errno)); + MXS_ERROR("Hangup in session that is not ready for routing: %s", mxs_strerror(err)); } } }