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

ErrorHandler in SetErrorHandler() is not called for certain exceptions #2190

Open
3 of 8 tasks
Bobsson opened this issue Feb 13, 2024 · 0 comments
Open
3 of 8 tasks

Comments

@Bobsson
Copy link

Bobsson commented Feb 13, 2024

Description

For some reason I can't figure out, several types of errors when trying to send a message with a built ProducerBuilder on which I've called SetErrorHandler() are not triggering that error handler. When I run the below code in LinqPad, which triggers a MsgSizeTooLarge error, I would expect to see the "Error Handler" block be output, but instead I get the "Thrown error" block with a ProduceException with "Broker: Message size too large".

I get the same behavior when the bootstrap server is unreachable (and thus get a "Local: Message timed out" error).

I do not get the same behavior when the bootstrap server is reachable but the username/password is corrupt. In that case, I get the error handler called three times, plus the caught exception.

I also do not get the same behavior when using the producer.Produce() method. Using that, the event handler is never called in any of those three scenarios, although the MsgSizeTooLarge will still throw an exception (but the unreachable server doesn't).

I'm using the 2.3.0 Nuget package in LinqPad 7.8.7, against Azure EventHub's Kafka interface. The debug logs don't show anything that indicates why the error handler would be called some of the time and not others, but I can provide them for any of the above six scenarios on request.

How to reproduce

var config = new Confluent.Kafka.ProducerConfig
{
	BootstrapServers = "*******.servicebus.windows.net:9093",
	SecurityProtocol = SecurityProtocol.SaslSsl,
	SaslMechanism = SaslMechanism.Plain,
	SaslUsername = "$ConnectionString",
	SaslPassword = "Endpoint=sb://**********.servicebus.windows.net/;SharedAccessKeyName=*******;SharedAccessKey=**********",
	//Debug = "all",
	MessageTimeoutMs = 5000,
};

//var message = new string('0', 1*1024); // Normal-sized message
var message = new string('0', 1*1024*1024); // 1 MB of data, which is too big for EventHub

using (var producer = new ProducerBuilder<long, string>(config)
	.SetKeySerializer(Serializers.Int64)
	.SetValueSerializer(Serializers.Utf8)
	//.SetLogHandler ((x, y) => y.Message.Dump())
	.SetErrorHandler((x, y) => (x,y).Dump("Error Handler"))
	.Build())
{
	try
	{
		//producer.Produce("data", new Message<long, string> { Key = DateTime.UtcNow.Ticks, Value = message });
		await producer.ProduceAsync("data", new Message<long, string> { Key = DateTime.UtcNow.Ticks, Value = message });
	}
	catch (ProduceException<long,string> e) { e.Error.Dump("Thrown error"); }
}

Checklist

Please provide the following information:

  • A complete (i.e. we can run it), minimal program demonstrating the problem. No need to supply a project file.
  • Confluent.Kafka nuget version.
  • Apache Kafka version.
  • Client configuration.
  • Operating system.
  • Provide logs (with "debug" : "..." as necessary in configuration).
  • Provide broker log excerpts.
  • Critical issue.
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