question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

client `Disconnect ` method blocking issue in 2.6.x

See original GitHub issue

hello, I use nuget pkg 2.5.x in a wpf prism project,worked well. however when I upgarded to 2.6.x to the latest 2.6.x version.the client Disconnect method seems to blocking main thread.so I wonder if there were some changes in logic in the new version.

2.6 client code via dnspy

public void Disconnect()
{
	if (this.IsConnected)
	{
		Action<string> logger = this.Logger;
		if (logger != null)
		{
			logger(this._header + "disconnecting from " + this.ServerIpPort);
		}
		this._tokenSource.Cancel();
		this._dataReceiver.Wait();
		this._client.Close();
		this._isConnected = false;
		return;
	}
	Action<string> logger2 = this.Logger;
	if (logger2 == null)
	{
		return;
	}
	logger2(this._header + "already disconnected");
}

2.5.4 client code via dnspy

public void Disconnect()
{
	if (this.IsConnected)
	{
		Action<string> logger = this.Logger;
		if (logger != null)
		{
			logger(this._Header + "disconnecting from " + this.ServerIpPort);
		}
		this._TokenSource.Cancel();
		this._TokenSource.Token.WaitHandle.WaitOne();
		this._Client.Close();
		this._IsConnected = false;
		return;
	}
	Action<string> logger2 = this.Logger;
	if (logger2 == null)
	{
		return;
	}
	logger2(this._Header + "already disconnected");
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jchristncommented, Mar 21, 2023

Ah, yes, winforms 😃 it gets tricky with winforms. I’m not an expert, but I have experienced interaction with objects blocking the main thread in a forms app. Probably best to have it in a background task.

1reaction
czytcommented, Mar 10, 2022

Hi, yes, the issue with 2.5 was that Disconnect would return prior to the cancellation actually happening, so if you attempt to Start again, it would fail (in glorious fashion). The .Wait() was added to the DataReceiver task to make sure it had actually terminated prior to allowing Disconnect to return. If you want, you can always fire an unawaited task in your code to do this, i.e. Task.Run(() => client.Disconnect());

thanks for your reply!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to catch a client disconnection when sending a large ...
It removes on finalization (pre 2.6) or on phantom file reference (2.6.x). The easiest way to catch the disconnection is to call Files....
Read more >
MQTT disconnects - Tried keepalive but no go. ESP8266 ...
First of all most of the problems with mqtt disconnecting is because bugged esp core. Simply not working good with some wifi chips....
Read more >
Karma - Disconnected, because no message in 10000 ms. ...
Try @fluffynuts 's workaround above if you haven't (assuming you ran into the issue after an upgrade to 2.6.X), as it worked for...
Read more >
Analyzing Disconnects - Photon Fusion
Client SDKs provide disconnection callbacks and a disconnect cause. Use those to investigate the unexpected disconnects you are having. Here we list the...
Read more >
Reading 23: Sockets & Networking
The accept() method is blocking. If no client connection is pending, then accept() waits until a client arrives before returning a Socket object...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found