0

I have a query looking up postgres -tables inside a thread in jruby.

Although there is no difference two me, active record does not terminate with some of the queries in concern of some tables, although it does terminate with some other tables.

I checked if it depends on indezes of these tables, or their structure, but it does not, or I couldn't find it, restricted to all the structure I could differentiate.

So I coded the same algorithm using raw-sql and it worked.

Hence there must be a bug with gem 'activerecord-jdbcpostgresql-adapter', '>= 61.0-java'.

I use 'rails', '~> 6.1.0' and jruby-9.2.14.0.

It worked as follows: Thread.new { query = <<~SQL [...] SQL ActiveRecord::Base.connection.execute(query) }

It only works with some tables, but not with all: Thread.new { Table.where(p1: s1) }

Sadly I cannot give you a hint how to reproduce it so far, as I don't catch the difference of the tables. Ask me, if you have any background-inspired guess.

Theores
  • 13
  • 5
  • Hi! Welcome to StackOverflow. Please ensure that your question contains a [minimum, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). This will allow us to help you better. – Kartik Soneji Feb 19 '21 at 08:47
  • I described it as much, as I can. I will figure it out and publish the solution here. So far it seems to be a misconfiguration of the server, so I guessed too easy going regarding the interpretation of it as a "bug". – Theores Feb 20 '21 at 10:59

1 Answers1

0

As a workaround it is possible to restrict the number of threads called by something like.

array1 = [...]; thread_index = 0; max_threads = 2; index = 0; continue = true; result = []; threads = [] while continue; while thread_index < max_threads threads << Thread.new { if array1[index] == nil; continue = false; else; result << function(array1[index]); end } index += 1; thread_index += 1 end threads.join; thread_index = 0 end

So somehow the maximal number of threads is not looked up for all database tables?

Restricted to my degree of understanding I would say, the above workaround is not thread-save, as it might be, that a tread is used somehow external?!

Theores
  • 13
  • 5