Problems with CassandraContext disposal #40

Closed
crow-ua opened this Issue Jun 20, 2012 · 5 comments

Comments

Projects
None yet
2 participants

crow-ua commented Jun 20, 2012

I have following method in my test application :

    public static bool SetupKeyspace(string keyspaceName, Server server)
        {
            try
            {
                using (var db = new CassandraContext(keyspaceName, server))
                {
                    var keyspaceExists = db.KeyspaceExists(keyspaceName); //exception here
                    if (keyspaceExists)
                    {
                        db.DropKeyspace(keyspaceName);
                    }
            }
            catch (CassandraException exception)
            {
                //MessageBox.Show(exception.Message, "Database error");
                return false;
            }
        }

When user somehow enters incorrect connection data, KeyspaceExists throws CassandraException, method returns false, and then in few seconds ArgumentNullException is thrown in Connection.cs at line 80 in public bool IsOpen :
lock (_transport) // The value can not be null
That happens during context disposal i guess. Fixed error by putting "if (_transport == null) return false;" check before lock, but don't know if that's correct. What is the simplest way to detect if CassandraContext is valid?

Contributor

nberardi commented Jun 20, 2012

Thank you for reporting this. I will take a look at the issue.

nberardi was assigned Jun 20, 2012

Contributor

nberardi commented Jun 20, 2012

I have been trying to track this down forever. Because transport is only ever assigned to. However it just occurred to me that if you didn't assign the ConnectionType correctly to a defined enum transport would never be created.

https://github.com/managedfusion/fluentcassandra/blob/master/src/Connections/Connection.cs#L36

You say this only happens when the Keyspace is defined wrong? Do you happen to know what you put in the Keyspace to get this to occur? Because there is no case where this should happen. So I am very curious about this edge case.

@nberardi nberardi added a commit that referenced this issue Jun 20, 2012

@nberardi nberardi still having _transport is null issues. starting to think it is part …
…of an overly aggressive GC routine. issue #40
b6b4d57

@nberardi nberardi added a commit that referenced this issue Jun 20, 2012

@nberardi nberardi having the connection be disposed on connection close may be responsi…
…ble for issue #40 - not quite sure why dispose was being used here
a6ba523

@nberardi nberardi added a commit that referenced this issue Jun 20, 2012

@nberardi nberardi added some disposed exceptions to the connection. hopefully this will…
… help diagnose if his problem occurs in the future. issue #40
38b1243

nberardi closed this Jun 20, 2012

crow-ua commented Jun 20, 2012

I have an application that works with Cassandra cluster on few servers. There is a requirement to give client ability to change connection settings (ip, port) and default keyspace in which application will work. There is no information about which server is up at certain moment of time, also there is no information on keyspace (some users will work on existing ones, some will create new for their own purposes), so there is no possibility to maintain good client-side validation of parameters other then try to connect with them. That's what i'm doing by calling above described method. "Drop keyspace if exists" is only for test purposes, it have some drawbacks with keyspacename case-sensitivity, but they are server side and have nothing to do with Thrift/fluentcassandra. Error with disposal occured when i tried to establish connection with wrong server address and/or closed port. ConnectionType is default at this point, although i think it will be specified more precise later.

Contributor

nberardi commented Jun 20, 2012

Thanks for the info, I have been trying to track down this issue for a long time. I think I have made real progress with these sets of checkins. Please reopen this ticket if you see this issue again. Also you may be interested in 'TryDropKeyspace' which is similar to what you do above.

https://github.com/managedfusion/fluentcassandra/blob/master/src/CassandraContext.cs#L144

crow-ua commented Jun 21, 2012

Thanks, everything works fine know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment