Skip to content

Use Lifetime pattern in XMPP connection #62

@ForNeVeR

Description

@ForNeVeR

Let's use JetBrains.Dataflow.Lifetime here to prevent the following case:

  1. Thread 1 performs Volatile.Read (and reads the "good" client)
  2. Thread 2 performs Volatile.Write(None)
  3. Thread 1 starts to perform some calls on the client
  4. Thread 2 at the same time calls client.Dispose()

As the result, client could become disposed in parallel with some calls by thread 1, which is very bad (at least theoretically). It is in my opinion worse than any calls on a non-disposed client (even if it has already failed).

Here we should use the lifetime pattern and lifetime.Using, and instead of Volatile.Read we better call lifetime.ExecuteIfAlive that should prevent us from disposing a lifetime that has some ongoing calls on it.

Originally posted as a comment to #59

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions