diff options
| author | Adam <Adam@anope.org> | 2017-03-16 20:13:56 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2017-03-16 20:13:56 -0400 |
| commit | 516ab164f6fcfe641cbf296d1244ac957fb16fd1 (patch) | |
| tree | a273ef4d2398079963dc3cbb5190692364abece1 /modules | |
| parent | b2d028533dfb7d601f994621e7eee89857cb2927 (diff) | |
redis: check for socket errors when loading database on startup
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/database/db_redis.cpp | 14 | ||||
| -rw-r--r-- | modules/m_redis.cpp | 11 |
2 files changed, 22 insertions, 3 deletions
diff --git a/modules/database/db_redis.cpp b/modules/database/db_redis.cpp index 4db4e723a..0e8bfc5a9 100644 --- a/modules/database/db_redis.cpp +++ b/modules/database/db_redis.cpp @@ -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:*"); diff --git a/modules/m_redis.cpp b/modules/m_redis.cpp index 7945ab9cc..23865e815 100644 --- a/modules/m_redis.cpp +++ b/modules/m_redis.cpp @@ -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(); } |
