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

AmqpObject.State should be thread safe #77

Closed
nemakam opened this issue Sep 18, 2017 · 1 comment
Closed

AmqpObject.State should be thread safe #77

nemakam opened this issue Sep 18, 2017 · 1 comment

Comments

@nemakam
Copy link
Contributor

nemakam commented Sep 18, 2017

AmqpObject.State currently is a property on the object which is used to to implement methods like IsClosed(). Unless these are thread safe, they might not return the latest value. One of volatile/interlocked/lock should be used for this property.
Similar to Azure/azure-service-bus-dotnet#297

Sample code where this becomes an issue:

while (timeoutHelper.RemainingTime() > TimeSpan.Zero)
{
	IEnumerable<AmqpMessage> amqpMessages = null;
	var hasMessages = await Task.Factory.FromAsync(
		(c, s) => receiveLink.BeginReceiveRemoteMessages(maxMessageCount, DefaultBatchFlushInterval, timeoutHelper.RemainingTime(), c, s),
		a => receiveLink.EndReceiveMessages(a, out amqpMessages),
		this).ConfigureAwait(false);
	Exception exception;
	if ((exception = receiveLink.GetInnerException()) != null)
	{
		throw exception;
	}

	if (receiveLink.IsClosing())
	{
		break;
	}
}

In the above case, receiveLink.IsClosing() will not return true if the link (through linkManager) is closed on a different thread.

@xinchen10
Copy link
Member

Receive now throws when the link is closed.

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

2 participants