diff --git a/server/core/dcb.c b/server/core/dcb.c index 0180ea08d..e6a7abd82 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -388,25 +388,19 @@ DCB_CALLBACK *cb; */ { SESSION *local_session = dcb->session; + dcb->session = NULL; CHK_SESSION(local_session); - /*< - * Remove reference from session if dcb is client. - */ - if (local_session->client == dcb) { - local_session->client = NULL; - } /** * Set session's client pointer NULL so that other threads * won't try to call dcb_close for client DCB * after this call. */ - if (dcb->session->client == dcb) + if (local_session->client == dcb) { - spinlock_acquire(&dcb->session->ses_lock); - dcb->session->client = NULL; - spinlock_release(&dcb->session->ses_lock); + spinlock_acquire(&local_session->ses_lock); + local_session->client = NULL; + spinlock_release(&local_session->ses_lock); } - dcb->session = NULL; session_free(local_session); } } diff --git a/server/modules/protocol/mysql_backend.c b/server/modules/protocol/mysql_backend.c index f74a2eebe..639379f56 100644 --- a/server/modules/protocol/mysql_backend.c +++ b/server/modules/protocol/mysql_backend.c @@ -1153,7 +1153,12 @@ gw_backend_close(DCB *dcb) mysql_send_com_quit(dcb, 0, quitbuf); mysql_protocol_done(dcb); - + /** + * The lock is needed only to protect the read of session->state and + * session->client values. Client's state may change by other thread + * but client's close and adding client's DCB to zombies list is executed + * only if client's DCB's state does _not_ change in parallel. + */ spinlock_acquire(&session->ses_lock); /** * If session->state is STOPPING, start closing client session. @@ -1162,15 +1167,13 @@ gw_backend_close(DCB *dcb) if (session != NULL && session->state == SESSION_STATE_STOPPING && session->client != NULL) - { - client_dcb = session->client; - - if (client_dcb->state == DCB_STATE_POLLING) + { + if (session->client->state == DCB_STATE_POLLING) { spinlock_release(&session->ses_lock); /** Close client DCB */ - dcb_close(client_dcb); + dcb_close(session->client); } else {