Skip to content

Lock when writing to an SslStream #418

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

Merged
merged 2 commits into from
May 14, 2018
Merged

Conversation

kjnilsson
Copy link
Contributor

@kjnilsson kjnilsson commented Apr 25, 2018

Network stream supports socket writes from multiple threads. SslStream
does not hence we need to lock before writing when using Ssl.

[#157088466]

May fix #417

Network stream supports socket writes from multiple threads. SslStream
does not hence we need to lock before writing when using Ssl.

[#157088466]
@@ -238,7 +237,7 @@ public void Close()
{
if (Model.IsOpen)
{
lock(m_basicCancelLock)
lock(Model)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a good idea. Model is passed in to Subscription, and it's a public property. That means that anything could potentially take a lock on the Model instance, and interfere with this code.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I'm not sure you should ever take a lock on a public reference. It's deadlock territory.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not a good idea as you say. We could lock on something inside the Model instead. I guess all rpcs inside a need to be locked over using a single lockobject per model as they cannot be pipelined.

@kjnilsson
Copy link
Contributor Author

As rpc methods cannot be pipelined we may as well lock around them.

[#157088466]
@kjnilsson kjnilsson force-pushed the rabbtimq-dotnet-client-417 branch from 546ea94 to c428e03 Compare May 8, 2018 20:01
@kjnilsson
Copy link
Contributor Author

This PR also includes locking around each RPC methods. As we cannot pipeline RPC calls we might as well lock around it. Combined with writing full frames this should increase model thread safety a fair bit.

@kjnilsson kjnilsson changed the title DO NOT MERGE: Lock when writing to an SslStream Lock when writing to an SslStream May 8, 2018
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

Successfully merging this pull request may close these issues.

The Write method cannot be called when another write operation is pending
4 participants