mondrian-rest icon indicating copy to clipboard operation
mondrian-rest copied to clipboard

Fix/init data race

Open hwchen opened this issue 5 years ago • 2 comments

@jazzido @jspeis just wanted to start the conversation about patching the race condition on connection init.

As far as I can tell, this patch fixes NilClass errors that were occurring when there were near-simultaneous requests to MondrianRest.

Previously, constructing the connection and connecting occurred on the first api request. Since connecting took some time, there would be a moment when @@olap was no longer nil, but the new mondrian connection was not yet ready for use (resulting in, we think, the NilClass errors).

With this patch, now those initialization steps are done in the config.ru.

mondrian_conn = Mondrian::OLAP::Connection.new(PARAMS)
mondrian_conn.connect
Mondrian::REST::APIHelpers.class_variable_set('@@olap', mondrian_conn)

use Rack::Config do |env|
  env['mondrian-olap.conn'] = mondrian_conn
end

There's probably a better way to do this, so please let us know what you think @jazzido . This would be a pretty big breaking change if it had to be done in config.ru

hwchen avatar Oct 22 '18 21:10 hwchen

Oops, doesn't fix. Increasing the threads and the NilClass behavior returns.

hwchen avatar Oct 22 '18 21:10 hwchen

Ok, so some modifications and it looks like nilClass has not returned.

Changing the reference from olap to @@olap in get_cubes_or_404 appeared to get rid of the last NilClass.

hwchen avatar Oct 23 '18 18:10 hwchen