mirror of
https://github.com/anope/anope.git
synced 2026-07-03 19:03:14 +02:00
redis: check for socket errors when loading database on startup
This commit is contained in:
@@ -58,6 +58,8 @@ namespace Redis
|
||||
public:
|
||||
Provider(Module *c, const Anope::string &n) : Service(c, "Redis::Provider", n) { }
|
||||
|
||||
virtual bool IsSocketDead() = 0;
|
||||
|
||||
virtual void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) = 0;
|
||||
virtual void SendCommand(Interface *i, const Anope::string &str) = 0;
|
||||
|
||||
|
||||
@@ -179,6 +179,12 @@ class DatabaseRedis : public Module, public Pipe
|
||||
|
||||
EventReturn OnLoadDatabase() anope_override
|
||||
{
|
||||
if (!redis)
|
||||
{
|
||||
Log(this) << "Unable to load database - unable to find redis provider";
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
const std::vector<Anope::string> type_order = Serialize::Type::GetTypeOrder();
|
||||
for (unsigned i = 0; i < type_order.size(); ++i)
|
||||
{
|
||||
@@ -186,7 +192,13 @@ class DatabaseRedis : public Module, public Pipe
|
||||
this->OnSerializeTypeCreate(sb);
|
||||
}
|
||||
|
||||
while (redis->BlockAndProcess());
|
||||
while (!redis->IsSocketDead() && redis->BlockAndProcess());
|
||||
|
||||
if (redis->IsSocketDead())
|
||||
{
|
||||
Log(this) << "I/O error while loading redis database - is it online?";
|
||||
return EVENT_CONTINUE;
|
||||
}
|
||||
|
||||
redis->Subscribe(&this->sl, "__keyspace@*__:hash:*");
|
||||
|
||||
|
||||
+9
-2
@@ -157,6 +157,11 @@ class MyRedisService : public Provider
|
||||
}
|
||||
|
||||
public:
|
||||
bool IsSocketDead() anope_override
|
||||
{
|
||||
return this->sock && this->sock->flags[SF_DEAD];
|
||||
}
|
||||
|
||||
void SendCommand(RedisSocket *s, Interface *i, const std::vector<Anope::string> &cmds)
|
||||
{
|
||||
std::vector<std::pair<const char *, size_t> > args;
|
||||
@@ -201,9 +206,11 @@ class MyRedisService : public Provider
|
||||
public:
|
||||
bool BlockAndProcess() anope_override
|
||||
{
|
||||
this->sock->ProcessWrite();
|
||||
if (!this->sock->ProcessWrite())
|
||||
this->sock->flags[SF_DEAD] = true;
|
||||
this->sock->SetBlocking(true);
|
||||
this->sock->ProcessRead();
|
||||
if (!this->sock->ProcessRead())
|
||||
this->sock->flags[SF_DEAD] = true;
|
||||
this->sock->SetBlocking(false);
|
||||
return !this->sock->interfaces.empty();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user