From 5f9c71e2b62590425f415a8fd725717b0c9dbd93 Mon Sep 17 00:00:00 2001 From: ZouJinHai Date: Fri, 27 Nov 2020 20:41:57 +0800 Subject: [PATCH] Fix ERR no server connection avaliable --- src/ServerGroup.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ServerGroup.cpp b/src/ServerGroup.cpp index e5d088c..5e4cb74 100644 --- a/src/ServerGroup.cpp +++ b/src/ServerGroup.cpp @@ -49,14 +49,16 @@ Server* ServerGroup::getServer(Handler* h, Request* req) const Server* serv = nullptr; if (req->requireWrite()) { int cnt = mServs.size(); - for (int i = 0; i < cnt; ++i) { + for (int i = cnt-1; i >= 0; --i) { Server* s = mServs[i]; if (!s->online()) { continue; } if (s->role() == Server::Master) { serv = s; - break; + if (!s->fail()){ + break; + } } } } else if (auto dataCenter = mPool->proxy()->dataCenter()) {