confluentinc / confluent-kafka-dotnet

Confluent's Apache Kafka .NET client
https://github.com/confluentinc/confluent-kafka-dotnet/wiki
Apache License 2.0
18 stars 852 forks source link

Deadlock issue in Confluent.SchemaRegistry project #515

Open lixiandai opened 6 years ago

lixiandai commented 6 years ago

Description

Confluent.SchemaRegistry/Rest/RestService.cs file

     public async Task<int> RegisterSchemaAsync(string subject, string schema)
            => (await RequestAsync<SchemaId>(
                    $"/subjects/{subject}/versions", 
                    HttpMethod.Post, 
                    new SchemaString(schema))).Id;

changed to

  public async Task<int> RegisterSchemaAsync(string subject, string schema)
            => (await RequestAsync<SchemaId>(
                    $"/subjects/{subject}/versions",
                    HttpMethod.Post,
                    new SchemaString(schema)).ConfigureAwait(false)).Id;

Confluent.SchemaRegistry/CachedSchemaRegistryClient.cs file Line 169

schemaId = restService.RegisterSchemaAsync(subject, schema).Result;

changed to schemaId =restService.RegisterSchemaAsync(subject,schema).ConfigureAwait(false).GetAwaiter().GetResult();

How to reproduce

I am facing some deadlock issue when calling restService.RegisterSchemaAsync(subject, schema). By looking into this http://blog.stephencleary.com/2012/07/dont-block-on-async-code.html Seems we should use ConfigureAwait(false) as much as possible in the aysc code pipeline.

Since the permission issue i am not able to open a pull request for the issue i am facing, so have to attach the code change we made locally to make the deadlock gone.

Checklist

Please provide the following information:

mhowlett commented 6 years ago

thanks @lixiandai - noted. see also #449.

lixiandai commented 6 years ago

@mhowlett thanks for the quick replay. could you give us a timeline when this fix will be able to merged back into 0.11.4 nuget package?

ravi-sontale commented 5 years ago

@mhowlett I am facing the same issue calling RegisterSchemaAsync. I have upgraded to 1.0-Experiential-7 of Confluent.Kafka, Confluent.Kafka.Avro and Confluent.SchemaRegistry. I'm producing the kafka event from web api on each request. I have async method which calls producer.ProduceAsync. I'm getting following error: "message": "An error has occurred.", "exceptionMessage": "A task was canceled.", "exceptionType": "System.Threading.Tasks.TaskCanceledException",

I have tried adding ConfigureAwait(false) to producer.ProduceAsync. Still no luck.

Could you please tell me what could be the issue?

If you use the AvroSpecific example which is console app it works fine.

mhowlett commented 5 years ago

thanks for the confirming this is still an issue @ravi-sontale. we merged some work towards resolving this, but didn't finish / test. Are you experiencing this issue in a WindowsForms app? when testing?

ravi-sontale commented 5 years ago

I am facing this issue when I’m trying to produce event from .net web api.

anchitj commented 1 month ago

Is this still an issue?