fix(libxce-failover): correct endpoint reconnect on rotate — re-bind iomgr + re-arm handlers (fixes endpoint_connect SEGV during live failover)

xce_failover_rotate reconnected with endpoint_fini+endpoint_init+endpoint_connect
but never re-bound ep->iomgr (reset by endpoint_init) nor re-armed the owner/
msg/err handlers + iomgr_monitor. endpoint_connect then dereferenced a NULL
iomgr (->ssl_ctx) → SEGV at netio.c:672 during live master failover. Added
xce_ctx_reconnect() in xcectx.c that mirrors xcecli_start's establishment
(without restarting iomgr/vtaskmgr or touching ctx->state); rotate delegates to
it. Found via live 3-node E2E. bug-610.
This commit is contained in:
Rongsong Shen 2026-06-17 06:53:46 +00:00
parent 312bd6be34
commit ffc2c590f9
4 changed files with 95 additions and 18 deletions

View file

@ -139,24 +139,17 @@ int xce_failover_rotate(api_ctx_t *ac)
if (rc < 0)
return rc;
/* Close the stale connection FIRST, then reconnect the SAME endpoint
* object so reply routing to ctx->wbuf (via ctx->ep == &ac->ep) is
* preserved. endpoint_fini() closes the fd, frees the SSL session, and
* clears handlers/peer; endpoint_init() recreates the socket fd and
* re-arms the object before endpoint_connect() drives the handshake.
*
* The live socket/handshake path is exercised by the E2E task (6.2); this
* wrapper keeps the I/O surface thin around the pure selector above. */
endpoint_fini(&ac->ep);
rc = endpoint_init(&ac->ep, AF_INET, SOCK_STREAM, 0, 0);
if (rc < 0)
return rc;
endpoint_set_peer(&ac->ep, &ac->ctx.myinfo);
rc = endpoint_connect(&ac->ep, host, (int)port);
return rc < 0 ? rc : 0;
/* Re-establish the SAME endpoint object on a fresh connection to the chosen
* target. xce_ctx_reconnect() (xcectx.c) owns the full connection setup that
* endpoint_fini drops — close old fd/SSL, recreate the socket, RE-BIND the
* iomgr (endpoint_connect needs ep->iomgr->ssl_ctx — a missing re-bind here
* previously crashed in endpoint_connect), drive the SSL handshake, and
* re-arm the endpoint in the running iomgr with its owner + msg/err handlers
* and re-monitor the new fd so replies route to ctx->wbuf and RDHUP failover
* re-arms. It does not restart iomgr/vtaskmgr or touch ctx->state (the loop's
* xcecli_ctx_recover owns the ERR→RUN reset). The live socket/handshake path
* is exercised by the E2E task (6.2). */
return xce_ctx_reconnect(&ac->ctx, host, (int)port);
}
/* ════════════════════════════════════════════════════════════════════════