-
Notifications
You must be signed in to change notification settings - Fork 162
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
How to handle "Could not connect to broker"? #298
Comments
The problem is also hard to handle when implementing my own custom consumer :
As I cannot try/catch the Line 70 in 236629e
It all stems from this kafka_ex/lib/kafka_ex/server.ex Line 393 in 236629e
|
I've wrestled with how to solve this a few times.
I believe the library handles this appropriately because catching the error and not crashing would introduce problems with applications that rely on kafka for their basic function. Put another way: how would kafka_ex tell the application that it lost the kafka connection? As for how to handle this to prevent crashes, are you seeing this on application startup, or if the brokers all go away while the application is already started? |
That is a good question, my original question is really only aimed at application startup, and the handling of errors connecting initially.
Initially yes, so I dug in and thought I'd wrap the KafkaEx.ConsumerGroup setup within my own supervisor so I can handle connection problems and reconnecting etc. But as you can see from above, the It could well be my lack of knowledge at handling this, but I could not find a way of either
This is currently a startup issue, I've not tested if the brokers disappear, but I am less concerned about that use case as if they go, we have bigger issues! |
I suspect that we'd fix this by maybe returning |
I did look at this, but to my current knowledge I belive its hard to do, as the raise is within the Supervisor callstack and not something we can rescue from, AFICT.
To me, that sounds really good, I was almost going in that direction anyway, so will have a play and see if what I can do looks any good. Thanks for your help and advice. |
Thinking out loud on here, and having had a quick play, it may be more involved than I first thought.
https://hexdocs.pm/elixir/Supervisor.html#start_link/2 I think the only/correct way to solve is to separate supervisor/server init phases from kafka connecting phases, such that once the supervision tree(s) are setup, and then the genservers, they I'm not sure on your thoughts on that, but its more than a "quick" fix, but I am willing to have a play if you believe it might be a good avenue to explore? |
@IanVaughan We're always open to pull requests. I think being able to handle this sort of thing gracefully would be a good idea if you're open to doing the pull request. |
@joshrotenberg thats good news, as I am 50% way done with a bit of a reorg. A brief overview is that I've split the More details to follow, I will push an MR when its looking ready, and welcome any advice. |
@IanVaughan @joshuawscott I've just discovered the joy of my app blowing up when there are no Kafka brokers available because of this raise. It'd be awesome to have an option to avoid that pain. To be specific, I'd love to see an error message get logged instead having an exception get raised. Here's an example of the behavior I'd love to see:
|
I have a somewhat related issue. I need to connect to brokers dynamically, not statically. Having the broker defined in config is a huge problem for me. I would love to see the app startup sequence be simply setting up the server processes and then have the connection be done via API rather than all the config values being global. There could be a startup option to do the simple case, but currently there is no way that I can see to redirect to a different broker at run-time. |
@technomage KafkaEx supports runtime configuration: |
Interesting but not addressing my problem. In my app the user selects a cluster/set of brokers from the UI and I need to point to the brokers at runtime after the app is up and running. And to be able to add another set of brokers, or change to another set of brokers at a later time as well. |
I could live with having Kafka_ex not start up at app startup and manually starting it then shutting it down between broker selections. But, currently the brokers have to be identified and fixed at server startup which is not a good use case for us. |
Can you open a new issue for this? it doesn't seem related to the original crash reported here. |
ok |
@technomage does the ideas recommended here: https://github.com/kafkaex/kafka_ex#use-kafkaex-with-a-pooling-library not work for you? also here: https://github.com/kafkaex/kafka_ex#create-a-kafkaex-worker under the
section |
and you probably want this too: Lines 36 to 39 in 76c752b
|
Thanks. I did not get from the docs how these fit together. I will try that. |
I have the same issue. I have a server running with Apache Kafka. Even if I try to open the URL from the browser I get a message from the Kafka log, however when I start my elixir application with kafka_ex I get the following error and I never receive nothing in the Kafka log:
Could you explain to me, what can be this error? |
@Yamilquery your issue is DNS related, you should confirm you can resolve the hostname from the same place the application is running, e.g:
|
Thank you very much, I solve it! |
If the Kafka broker is not present/found, then the
KafkaEx.ConsumerGroup
crashes, which brings down the whole app.The error comes from the result from
create_worker/2
kafka_ex/lib/kafka_ex/consumer_group/manager.ex
Line 96 in 236629e
Which returns
case
on the start_worker/2 line to check the:error
return? (If so I am happy to have a go at submitting that)I am using master from KafkaEx, and am starting the
KafkaEx.ConsumerGroup
as part of my main ApplicationSupervisor.start_link
:The text was updated successfully, but these errors were encountered: