Skip to content

Commit

Permalink
we should not clear the timeout error in normal case, and only clear …
Browse files Browse the repository at this point in the history
…it when consuming published message
  • Loading branch information
sewenew committed Oct 18, 2019
1 parent b4d1d0a commit 6fa030b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/sw/redis++/connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ class Connection {
return _ctx->err != REDIS_OK;
}

void reset() noexcept {
_ctx->err = 0;
}

void reconnect();

auto last_active() const
Expand Down
3 changes: 1 addition & 2 deletions src/sw/redis++/errors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ void throw_error(redisContext &context, const std::string &err_info) {

switch (err_code) {
case REDIS_ERR_IO:
if (errno == EAGAIN) {
context.err = 0;
if (errno == EAGAIN || errno == EINTR) {
throw TimeoutError(err_msg);
} else {
throw IoError(err_msg);
Expand Down
8 changes: 7 additions & 1 deletion src/sw/redis++/subscriber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ void Subscriber::punsubscribe(const StringView &pattern) {
void Subscriber::consume() {
_check_connection();

auto reply = _connection.recv();
ReplyUPtr reply;
try {
reply = _connection.recv();
} catch (const TimeoutError &) {
_connection.reset();
throw;
}

assert(reply);

Expand Down

0 comments on commit 6fa030b

Please sign in to comment.