Could not receive a master heartbeat within the specified interval
wangengzheng opened this issue · comments
Thank you so much for writing a great thing
The following error makes me question
Can't use multiple BinlogClients?
This error occurs when running two binlogclients on my computer
ConnectionOptions.Username is different
ConnectionOptions.Hostname is different
ConnectionOptions.ServerId is different
System.TimeoutException: Could not receive a master heartbeat within the specified interval
at MySqlCdc.TimeoutExtensions.WithTimeout[TResult](Task`1 task, TimeSpan timeoutSpan, String timeoutMessage)
at MySqlCdc.Network.EventStreamChannel.ReadPacketAsync(TimeSpan timeout, CancellationToken cancellationToken)+MoveNext()
at MySqlCdc.Network.EventStreamChannel.ReadPacketAsync(TimeSpan timeout, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
at MySqlCdc.BinlogClient.Replicate(CancellationToken cancellationToken)+MoveNext()
at MySqlCdc.BinlogClient.Replicate(CancellationToken cancellationToken)+MoveNext()
at MySqlCdc.BinlogClient.Replicate(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
var client = new BinlogClient(options =>
{
options.Hostname = _syncSetting.Hostname;
options.Database = _syncSetting.Database;
options.ServerId=_syncSetting.ServerId;
options.Port = _syncSetting.Port;
options.Username =_syncSetting.UserName;
options.Password = _syncSetting.Password;
options.SslMode = MySqlCdc.Constants.SslMode.REQUIRE;
options.HeartbeatInterval = TimeSpan.FromSeconds(30);
options.Blocking = true;
options.Binlog = BinlogOptions.FromEnd();
});
await foreach (var binlogEvent in client.Replicate(stoppingToken))
{
Log.Information("{@event}",binlogEvent);
}
Similar code
Hi @wangengzheng,
I'm on a vacation and can't test the scenario you described but I think BinlogClient should support the case.
MySQL supports multiple replicas of the same master server so multiple BinlogClients should work.
In fact, they need to have different ServerId. The ServerId must be unique for each replica including BinlogClient
Try to run two BinlogClient in two different .NET threads(using Task.Run) and see if your problem is solved.
Maybe there is some kind of deadlock in your code, also the exception happened to me once when the master server was too busy(processed multiple insert requests).
Thank you so much for taking the time to reply.
I will try more examples.
MySQL supports multiple replicas of the same master server so multiple BinlogClients should work.
This information is very helpful to me. Thank you and wish you a pleasant journey