NEventStore / NEventStore.Persistence.SQL

SQL Persistence Engine for NEventStore
MIT License
10 stars 33 forks source link

PollingClient: There is already an open DataReader associated with this Command which must be closed first. #11

Closed thomaseyde closed 9 years ago

thomaseyde commented 9 years ago

I was planning to set up my bounded contexts asynchronously and though setting up a PollingClient for each one would be easiest.

Update 3: https://github.com/NEventStore/NEventStore/issues/387

Update 2: After more investigation, eliminating the ClientPoller, it seems like the culprit is calling OpenStream() with a different bucketId. As far as I can tell, this is the very first call on this bucket, so why is there an open DataReader!?

Update: I was too hasty on this one. Ran a new test today, the synchronous code runs just fine. The problem starts when the poller interacts with asynchronous code!

Soon after my code runs, I get the following exception:

An exception of type 'NEventStore.Persistence.StorageUnavailableException' 
occurred in NEventStore.dll but was not handled in user code

Additional information: There is already an open DataReader associated with 
this Command which must be closed first.

As far as I can tell, I don't have direct access to any DataReader and find this error strange when I use the api. There's no way I can close it. That said, I haven't found any documentation for the PollingClient, so it could be experimental for what I know.

The PollingClient takes an IPersistStreams in its constructor, and the only way I have found to do that, is to pass store.Advanced:

var streams = Wireup.Init()
                    .UsingInMemoryPersistence()
                    .UsingSqlPersistence("EventStore").WithDialect(new MsSqlDialect())
                    .InitializeStorageEngine()
                    .UsingJsonSerialization()
                    .Build().Advanced;

poller = new PollingClient(streams, 500);

Each bounded context have their own instance of the store, so that shouldn't be the root cause:

Now, if an IPersisStreams is supposed to be disposed after each use, then I am kind of stuck because there is nowhere I can dispose it.

thomaseyde commented 9 years ago

So in the end this is not related to NEventStore after all. Add the following to the connection string:

MultipleActiveResultSets=True;

Thanks to http://stackoverflow.com/a/21131596/3282