Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect exception type when using Boost futures #534

Open
karzhenkov opened this issue Dec 8, 2023 · 4 comments · May be fixed by #536
Open

[BUG] Incorrect exception type when using Boost futures #534

karzhenkov opened this issue Dec 8, 2023 · 4 comments · May be fixed by #536

Comments

@karzhenkov
Copy link

The following program reports an exception of unknown type when REDIS_PLUS_PLUS_ASYNC_FUTURE is set to boost and there is no running Redis server:

#include <sw/redis++/async_redis++.h>
#include <iostream>

int main() {
  sw::redis::AsyncRedis redis("tcp://127.0.0.1:6379");
  try {
    if (auto value = redis.get("key").get()) {
      std::cout << "value: " << *value << std::endl;
    }
  } catch (const sw::redis::Error& e) {
    std::cerr << "[sw::redis::Error] " << e.what() << '\n';
  } catch (const std::exception& e) {
    std::cerr << "[std::exception] " << e.what() << '\n';
  } catch (...) {
    std::cerr << "[unknown error]\n";
  }
}

The output is as follows:

[unknown error]

Without REDIS_PLUS_PLUS_ASYNC_FUTURE, the output looks as expected:

[sw::redis::Error] failed to connect to Redis (127.0.0.1:6379): Connection refused

Environment:

  • OS: ubuntu
  • Compiler: gcc 13.2.0
  • hiredis version: v1.2.0
  • redis-plus-plus version: master, commit 5eccac2

Additional context
The problem might be related to using std::exception_ptr where boost::exception_ptr is needed.

@sewenew
Copy link
Owner

sewenew commented Dec 8, 2023

What's your boost version? The minimum version requirement for Boost is 1.55.0.

I'm not sure if this is a duplicated issue with this one.

Regards

@karzhenkov
Copy link
Author

Hi, @sewenew. My boost version is 1.74.0, so it should work. In addition, the issue you mentioned is about compile-time error. The problem reported here occurs at runtime.

@sewenew
Copy link
Owner

sewenew commented Dec 9, 2023

Thanks for pointing it out! I'll take a look into it.

Regards

@sewenew
Copy link
Owner

sewenew commented Dec 9, 2023

After some research, I found the problem lies on boost::promise::set(std::exception_ptr).

When something bad happens, e.g. failed to connect to Redis, we call promise::set to report error. When boost enabled, it's boost::promise. However, when we call boost::promise::set(std::exception_ptr), the exception type info loses.

So far, I do not find any cheaper solution to fix it. If you have any idea, feel free to let me know.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants