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

Callbacks and asynchronous exceptions #177

Open
torgeirsh opened this issue Jun 3, 2021 · 1 comment
Open

Callbacks and asynchronous exceptions #177

torgeirsh opened this issue Jun 3, 2021 · 1 comment

Comments

@torgeirsh
Copy link

I've made a producer with a delivery callback, and I can print to the console to verify that it's being called. However, if I call Control.Exception.throwTo from the delivery callback (with the main thread id), the next call to produceMessage hangs indefinitely. I can work around it by setting an MVar in the delivery callback instead, and call throwTo from the main thread when it's set, but it feels roundabout and cumbersome. (I know it's not necessary to use throwTo from the main thread, but I wanted to verify that using the exact same thread id works.) Why doesn't throwing from the delivery callback work? Should it work, or have I run into an FFI related snag?

@torgeirsh
Copy link
Author

After some investigation, it turns out that this is indeed an FFI snag. I've worked around it by spawning a thread that can throw the exception on behalf of the callback when signaled with an MVar. A better solution would perhaps be to allow throwing exceptions directly in the callback thread. That would require hw-kafka-client to catch any such exceptions when calling callbacks, somehow return them from pollEvents/pollConsumerEvents, and rethrow them "outside" FFI.

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

No branches or pull requests

1 participant